123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426 |
- package cn.com.taiji.zhongxiao.service;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- import java.util.Set;
- import java.util.Vector;
- import javax.inject.Inject;
- import javax.persistence.EntityManager;
- import javax.persistence.criteria.CriteriaBuilder;
- import javax.persistence.criteria.CriteriaBuilder.In;
- import javax.persistence.criteria.CriteriaQuery;
- import javax.persistence.criteria.Predicate;
- import javax.persistence.criteria.Root;
- import javax.persistence.criteria.Subquery;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.data.domain.Page;
- import org.springframework.data.domain.PageRequest;
- import org.springframework.data.domain.Sort;
- import org.springframework.data.domain.Sort.Direction;
- import org.springframework.data.domain.Sort.Order;
- import org.springframework.data.jpa.domain.Specification;
- import org.springframework.jdbc.core.JdbcTemplate;
- import org.springframework.jdbc.core.RowMapper;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Propagation;
- import org.springframework.transaction.annotation.Transactional;
- import cn.com.taiji.sys.domain.Dept;
- import cn.com.taiji.sys.domain.DeptRepository;
- import cn.com.taiji.sys.domain.Role;
- import cn.com.taiji.sys.domain.User;
- import cn.com.taiji.sys.domain.UserRepository;
- import cn.com.taiji.util.Constants;
- import cn.com.taiji.util.Pagination;
- import cn.com.taiji.util.StringTool;
- import cn.com.taiji.util.ToolUtil;
- import cn.com.taiji.zhongxiao.domain.TcodeSetRepository;
- import cn.com.taiji.zhongxiao.domain.TdataMeta;
- import cn.com.taiji.zhongxiao.domain.TdataMetaRepository;
- import cn.com.taiji.zhongxiao.dto.TdataMetaDto;
- @Service
- public class DatametaService extends BaseService {
- @Inject
- TinfoCodeService tinfoCodeService;
- @Value("${database_type}")
- String database_type;
- @Value("${admin_id}")
- String admin_id;
- @Value("${bmsh_role}")
- String bmsh_role;
- @Value("${zgbmsh_role}")
- String zgbmsh_role;
- @Inject
- EntityManager em;
- @Inject
- JdbcTemplate jdbcTemplate;
- @Inject
- TdataMetaRepository tdataMetaRepository;
- @Inject
- TcodeSetRepository tcodeSetRepository;
-
- @Inject
- DeptRepository deptRepository;
-
- @Inject
- UserRepository userRepository;
- // 获取所有角色列表
- @Transactional
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public Pagination<TdataMeta> findAllDatametaList(Map<String, Object> searchParameters, Pagination pageUtil,
- final TdataMetaDto dto,final User userInfo) {
- int page = 0;
- int pageSize = Constants.DEFAULT_ROWS;
- Page<TdataMeta> pageList;
- if (searchParameters != null && searchParameters.size() > 0 && searchParameters.get("page") != null) {
- page = Integer.parseInt(StringTool.null2Empty(searchParameters.get("page").toString())) - 1;
- }
- if (searchParameters != null && searchParameters.size() > 0 && searchParameters.get("pageSize") != null) {
- pageSize = Integer.parseInt(StringTool.null2Empty(searchParameters.get("pageSize").toString()));
- }
- if (pageSize < 1)
- pageSize = 1;
- if (pageSize > 1001)
- pageSize = 1000;
- List<Order> orders = new ArrayList<Sort.Order>();
- PageRequest pageable;
- Order order3 = new Order(Direction.DESC, "state");
- orders.add(order3);
- Sort sort = new Sort(orders);
- pageable = new PageRequest(page, pageSize, sort);
- if (dto != null) {
- Specification<TdataMeta> spec = new Specification<TdataMeta>() {
- @Override
- public Predicate toPredicate(Root<TdataMeta> root , CriteriaQuery<?> query, CriteriaBuilder cb) {
- List<Predicate> pl = new ArrayList<Predicate>();
- Set<Role> serRole = userInfo.getRoles();
- boolean flag = false;
- boolean flag_bmsh_role = false;
- boolean flag_zgbmsh_role = false;
- for (Role role : serRole) {
- if(admin_id.equals(role.getRoleId())&&!"3".equals(dto.getDescription()))
- flag = true;
- if(bmsh_role.equals(role.getRoleId())&&!"3".equals(dto.getDescription())){
- flag_bmsh_role=true;
- }
- if(zgbmsh_role.equals(role.getRoleId())&&!"3".equals(dto.getDescription())){
- flag_zgbmsh_role=true;
- }
- }
-
- if(dto.getId()!=null && dto.getId().length() > 0 ){
- pl.add(cb.like(root.<String>get("id"), "%" + dto.getId() + "%"));
- }
- if(dto.getMetaname()!=null && dto.getMetaname().length() > 0 ){
- pl.add(cb.like(root.<String>get("metaname"), "%" + dto.getMetaname() + "%"));
- }
- if(dto.getMetacode()!=null && dto.getMetacode().length() > 0 ){
- pl.add(cb.like(root.<String>get("metacode"), "%" + dto.getMetacode() + "%"));
- }
- if(dto.getDatacode()!=null && dto.getDatacode().length() > 0 ){
- pl.add(cb.like(root.<String>get("datacode"), "%" + dto.getDatacode() + "%"));
- }
- //提供方部门
- if(dto.getCreatorOrgname()!=null && dto.getCreatorOrgname().length() > 0 ){
- pl.add(cb.like(root.<String>get("creatorOrgname"), "%" + dto.getCreatorOrgname() + "%"));
- }
- if(dto.getDescription()!=null && dto.getDescription().length() > 0 ){
- In<Object> in = cb.in(root.get("state"));
- String description = dto.getDescription();
- String [] strArgs = description.split(",");
- for (String st : strArgs) {
- in.value(st);
- }
- pl.add(in);
- }
- if(dto.getState()!=null && dto.getState().length() > 0 ){
- pl.add(cb.equal(root.<String>get("state"), dto.getState()));
- }
- if(!(dto.getDescription()!=null && dto.getDescription().length() > 0&&"3".equals(dto.getDescription()) )){
- if(dto.getCreator() !=null&&!flag&&!flag_bmsh_role&&!flag_zgbmsh_role){
- pl.add(cb.or((cb.equal(root.get("creator") ,dto.getCreator()))));
- }}
- if(!flag&&("2,5".equals(dto.getDescription())||"3,4".equals(dto.getDescription())||dto.getCreator() !=null)){
- //代码集审核
- Predicate[] statList1 = new Predicate[2];
- if(flag_bmsh_role) {
- In<Object> in = cb.in(root.get("creatorOrg"));
- String []strArgs=dto.getCreatorOrg().split(",");
- Boolean exist=false;
- //获取当前用户所处机构
- for (String st : strArgs) {
- if(!ToolUtil.isNull(st)){
- in.value(st);
- exist=true;
- }
-
- }
- if(!exist){
- in.value("");
- }
- if("2,5".equals(dto.getDescription())) {
- statList1[0]=cb.and(in,cb.equal(root.get("state") ,"2"));
- }
- else {
- statList1[0]=cb.and(in,cb.or(
- cb.equal(root.get("state") ,"3")
- ,cb.equal(root.get("state") ,"4")
- ));
- }
- }
- if(flag_zgbmsh_role) {
- In<Object> in = cb.in(root.get("xzqhcode"));
- Boolean exist=false;
- //获取当前用户所处机构
- for (Dept st : userInfo.getDepts()) {
- in.value(st.getXzqhcode());
- exist=true;
- }
-
- if(!exist){
- in.value("");
- }
- if("2,5".equals(dto.getDescription())) {
- statList1[0]=cb.and(in,cb.equal(root.get("state") ,"5"));
- }
- else {
- statList1[0]=cb.and(in,cb.or(
- cb.equal(root.get("state") ,"3")
- ,cb.equal(root.get("state") ,"4")
- ));
- }
- }
- if(statList1[0]!=null&&statList1[1]!=null) {
- pl.add(cb.or(statList1));
- }
- else if(statList1[0]!=null) {
- pl.add(statList1[0]);
- }
- else if(statList1[1]!=null) {
- pl.add(statList1[1]);
- }
- }
-
- Predicate[] p = new Predicate[pl.size()];
- return cb.and(pl.toArray(p));
- }
- };
- pageList = tdataMetaRepository.findAll(spec, pageable);
- } else {
- Specification<TdataMeta> spec = new Specification<TdataMeta>() {
- public Predicate toPredicate(Root<TdataMeta> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
- List<Predicate> pl = new ArrayList<Predicate>();
- Predicate[] p = new Predicate[0];
- return cb.and(pl.toArray(p));
- }
- };
- pageList = tdataMetaRepository.findAll(spec, pageable);
- }
- List<TdataMeta> list = pageList.getContent();
- pageUtil.setPageResult(list);// 结果集
- pageUtil.setPageTotal(pageList.getTotalElements());// 总数
- pageUtil.setPageSize(pageSize);// 每页行数
- pageUtil.setPageCurrentNum(page + 1);// 当前页
- int totalPage = ((int) pageUtil.getPageTotal() + pageUtil.getPageSize() - 1) / pageUtil.getPageSize();
- pageUtil.setPageCount(totalPage);// 总页数
- return pageUtil;
- }
- public TdataMeta InsertRole(final TdataMetaDto dto) {
- TdataMeta cf = new TdataMeta();
- BeanUtils.copyProperties(dto, cf);
-
- cf.setId(ToolUtil.getUUID());
- return tdataMetaRepository.save(cf);
-
- }
- @Transactional(propagation = Propagation.SUPPORTS)
- public TdataMeta findTdataMetaById(String id) {
- TdataMeta cf = tdataMetaRepository.findOne(id);
- return cf;
- }
- public void updateTdataMeta(final TdataMetaDto dto, String createdate, String userId, String userName,
- String updatorOrg, String updateOrgName, String updatetime) {
- TdataMeta cf = tdataMetaRepository.findOne(dto.getId());
- cf.setDescription(dto.getDescription()); // 说明
- cf.setMetaname(dto.getMetaname());// 数据源名称
- cf.setDatasize(dto.getDatasize());// 长度
- cf.setRanges(dto.getRanges());// 值域
- // 数据源类别
- cf.setMetacodeid(dto.getMetacodeid());// 字符型 字典id
- cf.setMetacodeDis(dto.getMetacodeDis());
- cf.setMetacode(dto.getMetacode());// 字符型
- // 数据源类型
- cf.setDatatypeid(dto.getDatatypeid());
- cf.setDatatypeDis(dto.getDatatypeDis());
- cf.setDatatype(dto.getDatatype());
-
- cf.setCreatedate(createdate);
- cf.setUpdatetime(updatetime);
- cf.setUpdator(userId);
- cf.setUpdatorName(userName);
- cf.setUpdatorOrg(updatorOrg);
- cf.setUpdateOrgName(updateOrgName);
- tdataMetaRepository.saveAndFlush(cf);
- }
- @Transactional(propagation = Propagation.REQUIRED)
- public void deleteByTdataMeta(String id) {
- tdataMetaRepository.delete(id);
- }
- @Transactional(propagation = Propagation.REQUIRED)
- public void submintDatametaByIds(String id) {
- tdataMetaRepository.submintDatametaByIds(id);
- }
-
- @Transactional(propagation = Propagation.REQUIRED)
- public void audioSubmintDatametaByIds(String [] ids, String state) {
- if( ids!=null && ids.length>0 && !ids[0].isEmpty() ){
- if("3".equals(state) || "4".equals(state) ){
- tdataMetaRepository.audioSubmintDatametaByIds(ids, state);
- }
- }
-
- }
- @Transactional(propagation = Propagation.REQUIRED)
- public void audioTdataMeta(String checkdate, String checker, String checkerName, String checkerOrg,
- String checkerOrgName, String auditDescript, String state, String id,String metacode) {
- String datacode="";
- if("3".equals(state)){
- datacode=tinfoCodeService.getInfoCodeByPrecode("t_datameta"+metacode);
- if(datacode.length()<6)
- datacode=metacode+ToolUtil.lpad(datacode, 6, "0");
- else
- datacode=metacode+datacode;
- }
-
- tdataMetaRepository.audioTdataMeta(checkdate, checker, checkerName, checkerOrg, checkerOrgName, auditDescript, state, id,datacode );
- }
- public List<Map<String,Object>> findTdataMetaByIds(String ids) {
- // TODO Auto-generated method stub
-
- List<Map<String,Object>> list = jdbcTemplate.queryForList("select * from t_datameta where id in ("+ids+") ");
- // List list = tdataMetaRepository.findTdataMetaByIds(str);
- for (Map<String, Object> map : list) {
- map.put("STATE", state2Chinese(map.get("STATE").toString()) );
- }
-
- return list;
- }
-
- private static String state2Chinese(String STATE){
-
- switch (STATE) {
- case "1":
-
- return "保存";
- case "2":
-
- return "待审核";
- case "3":
-
- return "启用";
- case "4":
-
- return "停用";
- case "5":
-
- return "审核通过";
- case "6":
-
- return "退回修改";
- }
- return STATE;
- }
- public void saveInfoList(List<TdataMeta> resultList) {
- // TODO Auto-generated method stub
- tdataMetaRepository.save(resultList);
- }
- public List<TdataMetaDto> getAll(Vector<String> v1, String id) {
- StringBuffer sql=new StringBuffer("select id,metaname from t_datameta " );
- List<TdataMetaDto> infoList = new ArrayList<TdataMetaDto>();
- List<String> paramList=new ArrayList<String>();
- sql.append(" where id!=? and ");
- paramList.add(id);
- String s="";
-
- for(String str:v1){
- s+=str+"|";
- }
- if(!ToolUtil.isNull(s)){
- if("oracle".equals(database_type)){
- sql.append(" REGEXP_LIKE(metaname, ?) ");
- paramList.add(s.substring(0, s.length()-1)+"");
- }
- else if("mysql".equals(database_type)){
- sql.append(" metaname REGEXP ? ");
- paramList.add(s.substring(0, s.length()-1)+"");
- }
-
- }
- Object[] args = new Object[]{};
- int length = paramList.size();
- if(length>0){
- args=new Object[length];
- for(int i=0;i<length;i++){
- args[i] = paramList.get(i);
- }
-
- }
- infoList = jdbcTemplate.query(sql.toString(), args,
- new RowMapper<TdataMetaDto>() {
- @Override
- public TdataMetaDto mapRow(ResultSet rs, int rowNum)
- throws SQLException {
- TdataMetaDto info = new TdataMetaDto();
- info.setId(rs.getString("id"));
- info.setMetaname(rs.getString("metaname"));
- return info;
- }
- }
- );
-
- return infoList;
- }
- public List<TdataMeta> findTdataMetaByDatacode(String datacode) {
- // TODO Auto-generated method stub
- return tdataMetaRepository.findTdataMetaByDatacode(datacode);
- }
-
-
- }
|