package cn.com.goldenwater.dcproj.service.impl; import cn.com.goldenwater.dcproj.constValue.BisInspEnum; import cn.com.goldenwater.dcproj.constValue.CommonLabel; import cn.com.goldenwater.dcproj.constValue.SplitValue; import cn.com.goldenwater.dcproj.dao.*; import cn.com.goldenwater.dcproj.dto.BisInspCdepRgstrDto; import cn.com.goldenwater.dcproj.model.*; import cn.com.goldenwater.dcproj.param.*; import cn.com.goldenwater.dcproj.service.*; import cn.com.goldenwater.core.service.AbstractCrudService; import cn.com.goldenwater.dcproj.utils.AdLevelUtil; import cn.com.goldenwater.dcproj.utils.Constant; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import cn.com.goldenwater.id.util.UuidUtil; import javax.servlet.http.HttpServletResponse; import java.util.List; import java.util.Date; import java.util.Map; /** * @author lhc * @date 2020-11-19 */ @Service @Transactional public class BisInspCdepRgstrServiceImpl extends AbstractCrudService implements BisInspCdepRgstrService , BisInspObjStrategy { @Autowired private BisInspCdepRgstrDao bisInspCdepRgstrDao; @Autowired private AttCdepBaseDao attCdepBaseDao; @Autowired private BisInspCdepQuaService bisInspCdepQuaService; @Autowired private BisInspCdepBehService bisInspCdepBehService; @Autowired private BisInspCdepCapService bisInspCdepCapService; @Autowired private BisInspCdepConService bisInspCdepConService; @Autowired private BisInspPblmDao bisInspPblmDao; @Autowired private BisInspAllObjDao bisInspAllObjDao; @Autowired private AttCdepBaseService attCdepBaseService; public BisInspCdepRgstrServiceImpl(BisInspCdepRgstrDao bisInspCdepRgstrDao) { super(bisInspCdepRgstrDao); this.bisInspCdepRgstrDao = bisInspCdepRgstrDao; } @Override public int insert(BisInspCdepRgstr bisInspCdepRgstr) { String uuid = UuidUtil.uuid(); // 生成uuid bisInspCdepRgstr.setId(uuid); bisInspCdepRgstr.setIntm(new Date()); bisInspCdepRgstr.setUptm(new Date()); bisInspCdepRgstr.setDataStat("0"); return this.bisInspCdepRgstrDao.insert(bisInspCdepRgstr); } @Override public int update(BisInspCdepRgstr bisInspCdepRgstr) { bisInspCdepRgstr.setUptm(new Date()); int t = this.bisInspCdepRgstrDao.update(bisInspCdepRgstr); return t; } @Override public int delete(String id) { return this.bisInspCdepRgstrDao.delete(id); } @Override public void insertObj(BisInspAllObj bisInspAllObj, String persId) { BisInspCdepRgstr rgstr = new BisInspCdepRgstr(); AttCdepBase base = attCdepBaseDao.get(bisInspAllObj.getCode()); BeanUtils.copyProperties(base, rgstr); // 统一字段 rgstrId, objId rgstr.setId(UuidUtil.uuid()); rgstr.setObjId(bisInspAllObj.getObjId()); rgstr.setGroupId(bisInspAllObj.getId()); rgstr.setProvince(bisInspAllObj.getProvince()); // 日期 Date d = new Date(); rgstr.setIntm(d); rgstr.setUptm(d); rgstr.setBChkUnit(base.getDepName()); rgstr.setBDepCode(base.getDepCode()); // 数据状态 默认为 0 rgstr.setDataStat(CommonLabel.INIT_DATA); // 督查状态(0:未督查;1:督查中;2:已督查) rgstr.setState(CommonLabel.INIT_DATA); // 子表状态(0:未督查;1:督查中;2:已督查) rgstr.setQuaState(CommonLabel.INIT_DATA); rgstr.setBehState(CommonLabel.INIT_DATA); rgstr.setCapState(CommonLabel.INIT_DATA); rgstr.setConState(CommonLabel.INIT_DATA); // 创建人 rgstr.setPersId(persId); /* 添加 登记表 */ this.bisInspCdepRgstrDao.insert(rgstr); /* 添加 子表 */ BisInspCdepQua bisInspCdepQua = new BisInspCdepQua(); bisInspCdepQua.setRgstrId(rgstr.getId()); bisInspCdepQuaService.insert(bisInspCdepQua); BisInspCdepCap bisInspCdepCap = new BisInspCdepCap(); bisInspCdepCap.setRgstrId(rgstr.getId()); bisInspCdepCapService.insert(bisInspCdepCap); BisInspCdepCon bisInspCdepCon = new BisInspCdepCon(); bisInspCdepCon.setRgstrId(rgstr.getId()); bisInspCdepConService.insert(bisInspCdepCon); BisInspCdepBeh bisInspCdepBeh = new BisInspCdepBeh(); bisInspCdepBeh.setRgstrId(rgstr.getId()); bisInspCdepBehService.insert(bisInspCdepBeh); } @Override public String getType() { return BisInspEnum.CDEP.getValue(); } @Override public void cleanObjData(String objId) { BisInspCdepRgstrParam rgstrParam = new BisInspCdepRgstrParam(); rgstrParam.setObjId(objId); List list = this.bisInspCdepRgstrDao.findList(rgstrParam); if (list.size() > 0) { String id = list.get(0).getId(); // 删除子表 BisInspCdepQuaParam bisInspCdepQuaParam = new BisInspCdepQuaParam(); bisInspCdepQuaParam.setRgstrId(id); bisInspCdepQuaService.deleteBy(bisInspCdepQuaParam); BisInspCdepBehParam bisInspCdepBehParam = new BisInspCdepBehParam(); bisInspCdepBehParam.setRgstrId(id); bisInspCdepBehService.deleteBy(bisInspCdepBehParam); BisInspCdepConParam bisInspCdepConParam = new BisInspCdepConParam(); bisInspCdepConParam.setRgstrId(id); bisInspCdepConService.deleteBy(bisInspCdepConParam); BisInspCdepCapParam bisInspCdepCapParam = new BisInspCdepCapParam(); bisInspCdepCapParam.setRgstrId(id); bisInspCdepCapService.deleteBy(bisInspCdepCapParam); // 删除登记表 this.bisInspCdepRgstrDao.delete(id); } // 删除问题 BisInspPblmParam bisInspPblmParam = new BisInspPblmParam(); bisInspPblmParam.setObjId(objId); bisInspPblmParam.setObjType(BisInspEnum.CDEP.getValue()); bisInspPblmDao.deleteBy(bisInspPblmParam); // 删除对象名录表 BisInspAllObjParam bisInspAllObjParam = new BisInspAllObjParam(); bisInspAllObjParam.setObjId(objId); bisInspAllObjDao.deleteBy(bisInspAllObjParam); } @Override public PageInfo findObjPageByType(TypeParam typeParam, HttpServletResponse response) { if (StringUtils.isNotBlank(typeParam.getAdCode())) { typeParam.setAdCode(String.valueOf(AdLevelUtil.SubAd(typeParam.getAdCode()).get(SplitValue.SUBAD))); } PageHelper.startPage(typeParam); List list = this.bisInspCdepRgstrDao.findPageList(typeParam); return (PageInfo) new PageInfo(list); } @Override public Object findObjListByType(TypeParam typeParam) { return this.bisInspCdepRgstrDao.findPageList(typeParam); } @Override public BisInspCdepRgstr save(BisInspCdepRgstr bisInspCdepRgstr) { // 根据有无主键,来新增、更新信息 int ret = 0; if (StringUtils.isNotBlank(bisInspCdepRgstr.getRgstrId())) { // rgstrId 不为 空 时,传给ID bisInspCdepRgstr.setId(bisInspCdepRgstr.getRgstrId()); } if (StringUtils.isBlank(bisInspCdepRgstr.getId())) { if (StringUtils.isNotBlank(bisInspCdepRgstr.getObjId())) { BisInspCdepRgstrParam param = new BisInspCdepRgstrParam(); param.setObjId(bisInspCdepRgstr.getId()); BisInspCdepRgstr rgstr = getBy(param); // 如果没有注册表,添加 if (null == rgstr) { ret = insert(bisInspCdepRgstr); } else { bisInspCdepRgstr.setId(rgstr.getId()); bisInspCdepRgstr.setUptm(new Date()); update(bisInspCdepRgstr); // 更新基础表 updateAttCdepBase(bisInspCdepRgstr); } } } else { if (StringUtils.isBlank(bisInspCdepRgstr.getObjId())) { BisInspCdepRgstr rgstr = get(bisInspCdepRgstr.getId()); if (null != rgstr) { bisInspCdepRgstr.setObjId(rgstr.getObjId()); } } bisInspCdepRgstr.setUptm(new Date()); update(bisInspCdepRgstr); // 更新基础表 updateAttCdepBase(bisInspCdepRgstr); } return bisInspCdepRgstr; } private void updateAttCdepBase(BisInspCdepRgstr bisInspCdepRgstr) { // 清空特殊数据 if (StringUtils.isNotBlank(bisInspCdepRgstr.getObjId())) { AttCdepBase attCdepBase = attCdepBaseService.getObjId(bisInspCdepRgstr.getObjId()); // 转换基础表ID String attCdepBaseId = attCdepBase.getId(); BeanUtils.copyProperties(bisInspCdepRgstr, attCdepBase); attCdepBase.setId(attCdepBaseId); attCdepBase.setIntm(null); attCdepBaseService.update(attCdepBase); } } @Override public PageInfo findCdepPageInfo(BisInspCdepRgstrParam bisInspCdepRgstrParam) { PageHelper.startPage(bisInspCdepRgstrParam.getPageNum(),bisInspCdepRgstrParam.getPageSize()); List list = bisInspCdepRgstrDao.findCdepPageInfo(bisInspCdepRgstrParam); return new PageInfo(list); } @Override public void updateState(Map map) { BisInspCdepRgstr rgstr = get(MapUtils.getString(map, "rgstrId")); if (!Constant.STRING_TWO.equals(rgstr.getState()) && StringUtils.isNotBlank(MapUtils.getString(map, "state"))) { rgstr.setUptm(new Date()); rgstr.setState(Constant.STRING_ONE); switch (MapUtils.getString(map, "param")) { case "beh": rgstr.setBehState(MapUtils.getString(map, "state")); break; case "cap": rgstr.setCapState(MapUtils.getString(map, "state")); break; case "con": rgstr.setConState(MapUtils.getString(map, "state")); break; case "qua": rgstr.setQuaState(MapUtils.getString(map, "state")); break; default: } update(rgstr); } } }