| | |
| | | package com.lf.server.service.show; |
| | | |
| | | import com.lf.server.entity.all.StaticData; |
| | | import com.lf.server.entity.ctrl.DownloadReqEntity; |
| | | import com.lf.server.entity.show.ApplyEntity; |
| | | import com.lf.server.entity.show.FlowEntity; |
| | | import com.lf.server.entity.sys.UserEntity; |
| | | import com.lf.server.helper.Md5Helper; |
| | | import com.lf.server.helper.AesHelper; |
| | | import com.lf.server.helper.StringHelper; |
| | | import com.lf.server.mapper.show.ApplyMapper; |
| | | import org.hsqldb.rights.User; |
| | | import com.lf.server.service.data.MetaService; |
| | | import com.lf.server.service.sys.UserService; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.sql.Timestamp; |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | @Autowired |
| | | FlowService flowService; |
| | | |
| | | @Autowired |
| | | UserService userService; |
| | | |
| | | @Autowired |
| | | MetaService metaService; |
| | | |
| | | @Autowired |
| | | DataLibService dataLibService; |
| | | |
| | | private final static Log log = LogFactory.getLog(ApplyService.class); |
| | | |
| | | @Override |
| | | public Integer selectCount(Integer userid) { |
| | | return applyMapper.selectCount(userid); |
| | | public Integer selectCount(String uname, Integer status, Timestamp start, Timestamp end) { |
| | | uname = StringHelper.getLikeUpperStr(uname); |
| | | |
| | | return applyMapper.selectCount(uname, status, start, end); |
| | | } |
| | | |
| | | @Override |
| | | public List<ApplyEntity> selectByPage(Integer userid, Integer limit, Integer offset) { |
| | | return applyMapper.selectByPage(userid, limit, offset); |
| | | public List<ApplyEntity> selectByPage(Integer userid, String uname, Integer status, Timestamp start, Timestamp end, Integer limit, Integer offset) { |
| | | uname = StringHelper.getLikeUpperStr(uname); |
| | | |
| | | return applyMapper.selectByPage(userid, uname, status, start, end, limit, offset); |
| | | } |
| | | |
| | | @Override |
| | |
| | | @Override |
| | | public ApplyEntity selectById(int id) { |
| | | return applyMapper.selectById(id); |
| | | } |
| | | |
| | | @Override |
| | | public UserEntity selectUserByDepcode(String depcode) { |
| | | return applyMapper.selectUserByDepcode(depcode); |
| | | } |
| | | |
| | | @Override |
| | | public Integer selectSubmits(Integer userid) { |
| | | return applyMapper.selectSubmits(userid); |
| | | } |
| | | |
| | | @Override |
| | | public List<FlowEntity> selectFlows(Integer applyid) { |
| | | return applyMapper.selectFlows(applyid); |
| | | } |
| | | |
| | | @Override |
| | |
| | | return applyMapper.updates(list); |
| | | } |
| | | |
| | | @Override |
| | | public Integer updateForDiscard(Integer userid, Integer id) { |
| | | return applyMapper.updateForDiscard(userid, id); |
| | | } |
| | | |
| | | @Override |
| | | public Integer updateForResubmit(Integer userid, Integer id) { |
| | | return applyMapper.updateForResubmit(userid, id); |
| | | } |
| | | |
| | | @Override |
| | | public Integer updateForSubmit(Integer userid, Integer applyid, Integer flowId) { |
| | | return applyMapper.updateForSubmit(userid, applyid, flowId); |
| | | } |
| | | |
| | | @Override |
| | | public Integer updateForReject(Integer userid, Integer applyid, Integer flowId) { |
| | | return applyMapper.updateForReject(userid, applyid, flowId); |
| | | } |
| | | |
| | | /** |
| | | * 插入数据申请 |
| | | */ |
| | | public Integer insertApply(UserEntity ue, DownloadReqEntity dr) { |
| | | public Integer insertApply(UserEntity ue, DownloadReqEntity dr) throws Exception { |
| | | ApplyEntity apply = getApplyEntity(ue, dr); |
| | | int rows = applyMapper.insert(apply); |
| | | if (0 == rows) { |
| | |
| | | } |
| | | |
| | | List<FlowEntity> list = getFlowEntities(apply.getId(), ue, dr); |
| | | rows = flowService.inserts(list); |
| | | if (list.isEmpty()) { |
| | | applyMapper.delete(apply.getId()); |
| | | throw new Exception("找不到待审核人"); |
| | | } |
| | | |
| | | return rows; |
| | | return flowService.inserts(list); |
| | | } |
| | | |
| | | /** |
| | | * 获取数据申请实体类 |
| | | */ |
| | | private ApplyEntity getApplyEntity(UserEntity ue, DownloadReqEntity dr) { |
| | | String dbPwd = Md5Helper.reverse(Md5Helper.generate(dr.getPwd())); |
| | | private ApplyEntity getApplyEntity(UserEntity ue, DownloadReqEntity dr) throws Exception { |
| | | // String dbPwd = Md5Helper.reverse(Md5Helper.generate(dr.getPwd())) |
| | | String aesPwd = AesHelper.encrypt(dr.getPwd()); |
| | | String gids = null == dr.getIds() || dr.getIds().isEmpty() ? null : StringHelper.join(dr.getIds(), ","); |
| | | |
| | | ApplyEntity apply = new ApplyEntity(); |
| | | apply.setUserid(ue.getId()); |
| | | apply.setDepids(StringHelper.join(dr.getIds(), ",")); |
| | | apply.setDepids(StringHelper.join(dr.getDepcodes(), ",")); |
| | | apply.setTabs(StringHelper.join(dr.getTabs(), ",")); |
| | | apply.setEntities(StringHelper.join(dr.getEntities(), ",")); |
| | | apply.setWkt(dr.getWkt()); |
| | | apply.setPwd(dbPwd); |
| | | apply.setPwd(aesPwd); |
| | | apply.setStatus(0); |
| | | apply.setCount(dr.getIds().size()); |
| | | apply.setCount(dr.getDepcodes().size()); |
| | | apply.setDescr(dr.getDescr()); |
| | | apply.setCreateUser(ue.getId()); |
| | | apply.setDepcode(dr.getDepcode()); |
| | | apply.setDircodes(dr.getDirs()); |
| | | apply.setGids(gids); |
| | | apply.setFilters(dr.getFilter()); |
| | | |
| | | return apply; |
| | | } |
| | |
| | | */ |
| | | private List<FlowEntity> getFlowEntities(Integer applyId, UserEntity ue, DownloadReqEntity dr) { |
| | | List<FlowEntity> list = new ArrayList<>(); |
| | | for (Integer depid : dr.getIds()) { |
| | | UserEntity user = selectUserByDepid(depid); |
| | | for (String depcode : dr.getDepcodes()) { |
| | | UserEntity user = selectUserByDepcode(depcode); |
| | | if (null == user) { |
| | | user = userService.selectByUid(StaticData.ADMIN); |
| | | } |
| | | |
| | | FlowEntity flow = new FlowEntity(); |
| | | flow.setApplyid(applyId); |
| | | flow.setDepid(depid); |
| | | flow.setDepcode(depcode); |
| | | flow.setUserid(user.getId()); |
| | | flow.setStatus(0); |
| | | flow.setDescr(null); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 根据单位ID查询用户 |
| | | * 打包DB数据 |
| | | */ |
| | | private UserEntity selectUserByDepid(Integer depid) { |
| | | // |
| | | public void zipDbData(UserEntity ue, ApplyEntity entity) { |
| | | try { |
| | | List<String> entities = Arrays.asList(entity.getEntities().split(StaticData.COMMA)); |
| | | String pwd = AesHelper.decrypt(entity.getPwd()); |
| | | |
| | | return null; |
| | | DownloadReqEntity dr = new DownloadReqEntity(); |
| | | dr.setEntities(entities); |
| | | dr.setWkt(dr.getWkt()); |
| | | dr.setPwd(pwd); |
| | | dr.setDepcode(entity.getDepcode()); |
| | | dr.setDirs(entity.getDircodes()); |
| | | dr.setIds(getIds(entity)); |
| | | dr.setFilter(entity.getFilters()); |
| | | |
| | | String guid = "sysmeta".equals(entity.getEntities()) ? metaService.downloadMeteReq(ue, dr) : dataLibService.downloadDbReq(ue, dr); |
| | | if (!StringHelper.isEmpty(guid)) { |
| | | entity.setGuid(guid); |
| | | update(entity); |
| | | } |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取ID集合 |
| | | */ |
| | | private List<Integer> getIds(ApplyEntity entity) { |
| | | if (StringHelper.isEmpty(entity.getGids())) { |
| | | return null; |
| | | } |
| | | |
| | | List<Integer> list = new ArrayList<>(); |
| | | for (String str : entity.getGids().split(StaticData.COMMA)) { |
| | | list.add(Integer.parseInt(str)); |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | } |