| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498 |
- package cn.com.goldenwater.dcproj.service.impl.importex;
- import cn.com.goldenwater.core.service.AbstractCrudService;
- import cn.com.goldenwater.dcproj.dao.*;
- import cn.com.goldenwater.dcproj.dto.BisInspRgstrDto;
- import cn.com.goldenwater.dcproj.dto.BisInspSwhsRgstrPcDtoVo;
- import cn.com.goldenwater.dcproj.model.*;
- import cn.com.goldenwater.dcproj.param.*;
- import cn.com.goldenwater.dcproj.service.BisInspSwhsRgstrService;
- import cn.com.goldenwater.dcproj.service.ImpDcInfoService;
- import cn.com.goldenwater.dcproj.utils.BeanUtil;
- import cn.com.goldenwater.dcproj.utils.export.CreateExcelHelper;
- import cn.com.goldenwater.dcproj.utils.impexcel.ExpAndImpUtil;
- import cn.com.goldenwater.dcproj.utils.impexcel.ImportExcel;
- import cn.com.goldenwater.dcproj.utils.impexcel.format.DcSydFieldFormatExp;
- import cn.com.goldenwater.dcproj.utils.impexcel.format.DcSydFieldFormatImp;
- import cn.com.goldenwater.id.util.UuidUtil;
- import org.apache.commons.collections.MapUtils;
- import org.apache.commons.lang.ArrayUtils;
- import org.apache.commons.lang.StringUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.data.redis.core.RedisTemplate;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import javax.servlet.http.HttpServletResponse;
- import java.io.File;
- import java.io.IOException;
- import java.util.*;
- import java.util.stream.Collectors;
- import static cn.com.goldenwater.dcproj.utils.export.FieldFormat.formatCheckNull;
- import static cn.com.goldenwater.dcproj.utils.export.FieldFormat.formatState;
- import static cn.com.goldenwater.dcproj.utils.impexcel.field.ExcelFieldLists.*;
- /**
- * <p>
- * 批量填报
- * </p>
- *
- * @author liyz
- * @date 2019/8/14 13:34
- **/
- @Service
- @Transactional(rollbackFor = Exception.class)
- public class ImpDcInfoServiceImpl extends AbstractCrudService implements ImpDcInfoService {
- @Value("${export.templatePath}")
- private String templatePath;
- @Autowired
- private ImpDcInfoDao impDcInfoDao;
- @Autowired
- private BisInspAllDao bisInspAllDao;
- @Autowired
- private CreateExcelHelper createExcelHelper;
- @Autowired
- private BisInspSwhsRgstrDao bisInspSwhsRgstrDao;
- @Autowired
- private BisInspSwhsRgstrService bisInspSwhsRgstrService;
- @Autowired
- private AttSwhsBaseCrrctDao attSwhsBaseCrrctDao;
- @Autowired
- private BisInspSwhsRgstrSafetyDao bisInspSwhsRgstrSafetyDao;
- @Autowired
- private BisInspSwhsRgstrMeasuresDao bisInspSwhsRgstrMeasuresDao;
- @Autowired
- private AttSwhsBaseDao attSwhsBaseDao;
- @Autowired
- private RedisTemplate redisTemplate;
- public ImpDcInfoServiceImpl(ImpDcInfoDao impDcInfoDao) {
- super(impDcInfoDao);
- this.impDcInfoDao = impDcInfoDao;
- }
- @Override
- public void downloadTemplate(HttpServletResponse response, String userId, String orgType, String orgIds) throws Exception {
- // 模板路径
- String filePath = templatePath + File.separator + "tbSyd.xls";
- // SHEET名称
- String sheetName = "水源地填报表";
- // 文件名称带后缀
- String fileName = sheetName + ".xls";
- // startRow
- int startRow = 4;
- List<BisInspRgstrDto> rgstrList = this.getRgstrList(userId,orgIds);
- List<BisInspSwhsRgstrPcDtoVo> dtoVoList = this.getBisDtoVo(rgstrList,userId);
- List<Map<String,Object>> dataList = this.getExpDataList(dtoVoList);
- ExpAndImpUtil.download(response,dataList,filePath,startRow,sheetName);
- }
- public List<BisInspSwhsRgstrPcDtoVo> getBisDtoVo(List<BisInspRgstrDto> dataList, String userId) {
- List<BisInspSwhsRgstrPcDtoVo> dataListVo = new ArrayList<>();
- dataList.forEach(rgstrDto -> {
- BisInspSwhsRgstrPcDtoVo bisVo = new BisInspSwhsRgstrPcDtoVo();
- // 放入登记表
- bisVo.setBisInspSwhsRgstr(this.getBisInspSwhsRgstr(rgstrDto));
- // 放入通用登记表
- bisVo.setBisInspRgstrDto(rgstrDto);
- // 1.基本信息纠错表
- // 2.安全保障达标落实情况
- bisVo.setBisInspSwhsRgstrSafety(this.getBisInspSwhsRgstrSafety(rgstrDto));
- // 3.保护措施监管情况
- bisVo.setBisInspSwhsRgstrMeasures(this.getBisInspSwhsRgstrMeasures(rgstrDto));
- dataListVo.add(bisVo);
- });
- return dataListVo;
- }
- private BisInspSwhsRgstr getBisInspSwhsRgstr(BisInspRgstrDto rgstrDto){
- return bisInspSwhsRgstrDao.get(rgstrDto.getRgstrId());
- }
- private AttSwhsBaseCrrct getAttSwhsBaseCrrct(BisInspRgstrDto rgstrDto,String userId){
- CrrctParam crrctParam = new CrrctParam();
- crrctParam.setPersId(userId);
- crrctParam.setCode(rgstrDto.getCode());
- // 根据人员id 和 水源地编码
- AttSwhsBaseCrrctParam attSwhsBaseCrrctParam = new AttSwhsBaseCrrctParam();
- attSwhsBaseCrrctParam.setSwhsCode(rgstrDto.getCode());
- attSwhsBaseCrrctParam.setPersId(userId);
- if(StringUtils.isBlank(attSwhsBaseCrrctParam.getSwhsCode())){
- return new AttSwhsBaseCrrct();
- }else {
- AttSwhsBaseCrrct crrct = attSwhsBaseCrrctDao.getBy(attSwhsBaseCrrctParam);
- if (crrct == null) {
- AttSwhsBase base = attSwhsBaseDao.get(crrctParam.getCode());
- crrct = new AttSwhsBaseCrrct();
- BeanUtil.copyObject1(base,crrct);
- crrct.setId("");
- crrct.setSwhsCode(base.getId());
- }
- return crrct;
- }
- }
- private BisInspSwhsRgstrSafety getBisInspSwhsRgstrSafety(BisInspRgstrDto rgstrDto){
- BisInspSwhsRgstrSafetyParam bisInspSwhsRgstrSafetyParam = new BisInspSwhsRgstrSafetyParam();
- bisInspSwhsRgstrSafetyParam.setRgstrId(rgstrDto.getId());
- if(StringUtils.isBlank(bisInspSwhsRgstrSafetyParam.getRgstrId())){
- return new BisInspSwhsRgstrSafety();
- }else {
- return bisInspSwhsRgstrSafetyDao.getBy(bisInspSwhsRgstrSafetyParam);
- }
- }
- private BisInspSwhsRgstrMeasures getBisInspSwhsRgstrMeasures(BisInspRgstrDto rgstrDto){
- BisInspSwhsRgstrMeasuresParam bisInspSwhsRgstrMeasuresParam = new BisInspSwhsRgstrMeasuresParam();
- bisInspSwhsRgstrMeasuresParam.setRgstrId(rgstrDto.getId());
- if(StringUtils.isBlank(bisInspSwhsRgstrMeasuresParam.getRgstrId())){
- return new BisInspSwhsRgstrMeasures();
- }else {
- return bisInspSwhsRgstrMeasuresDao.getBy(bisInspSwhsRgstrMeasuresParam);
- }
- }
- private List<Map<String,Object>> getExpDataList(List<BisInspSwhsRgstrPcDtoVo> list){
- // 把实体类的数据放入到List里去
- List<Map<String, Object>> dataList = new LinkedList<>();
- for (BisInspSwhsRgstrPcDtoVo bis : list) {
- HashMap<String, Object> map = new HashMap<>();
- //通用登记表
- BisInspRgstrDto bisInspRgstrDto = bis.getBisInspRgstrDto();
- // 放入登记表主键
- map.put("rgstrId", bisInspRgstrDto.getId());
- // 督查组
- map.put("groupName", formatCheckNull(bisInspRgstrDto.getUpGroupName()));
- // 督查状态
- map.put("state", formatState(bisInspRgstrDto.getState()));
- // 改成放入登记表
- BisInspSwhsRgstr bisInspSwhsRgstr = bis.getBisInspSwhsRgstr();
- ExpAndImpUtil.convertBeanToMap(bisInspSwhsRgstr, attSwhsBaseCrrctArrays, map, DcSydFieldFormatExp.class);
- // 2.安全保障达标落实情况
- BisInspSwhsRgstrSafety bisInspSwhsRgstrSafety = bis.getBisInspSwhsRgstrSafety();
- ExpAndImpUtil.convertBeanToMap(bisInspSwhsRgstrSafety, bisInspSwhsRgstrSafetyArrays, map, DcSydFieldFormatExp.class);
- // 3.保护措施监管情况
- BisInspSwhsRgstrMeasures bisInspSwhsRgstrMeasures = bis.getBisInspSwhsRgstrMeasures();
- ExpAndImpUtil.convertBeanToMap(bisInspSwhsRgstrMeasures, bisInspSwhsRgstrMeasuresArrays, map, DcSydFieldFormatExp.class);
- dataList.add(map);
- }
- return dataList;
- }
- @Override
- public Map<String, Object> parseTemplate(String filePath, String userId, String orgType) {
- Map<String,Object> map = new HashMap<>();
- List<LinkedHashMap<String,Object>> listParse = null;
- int startRow = 4;
- int endRow = 0;
- List<LinkedHashMap<String, Object>> listShow = new ArrayList<>();
- try {
- // 获取到从Excel里提取到的数据,并已格式化
- listParse = ImportExcel.getParseData(filePath,startRow,endRow, DcSydFieldFormatImp.class);
- if(listParse.size() > 0){
- String cacheId = UuidUtil.uuid();
- redisTemplate.opsForList().rightPushAll(cacheId,listParse);
- map.put("cacheId",cacheId);
- }else{
- map.put("cacheId","");
- }
- listShow = ImportExcel.getShowData(listParse, DcSydFieldFormatExp.class);
- // 过滤掉不是此用户的节点
- listShow = this.filterNotTreeIdData(listShow, userId, null);
- map.put("listParse",listShow);
- } catch (IOException e) {
- e.printStackTrace();
- }
- return map;
- }
- @Override
- public String insertTemplateInfo(String cacheId, String userId, String orgType) {
- // 从redis里获取到数据
- List<LinkedHashMap<String, Object>> listParse = this.getParseDataByRedis(cacheId);
- // 过滤掉不是此用户的节点
- listParse = this.filterNotTreeIdData(listParse,userId,null);
- switch (orgType){
- case "013":
- return this.insertTemplateInfoSyd(listParse,userId);
- default:
- return null;
- }
- }
- /**
- * 添加入库从模板里获取到的水源地督查信息
- */
- private String insertTemplateInfoSyd(List<LinkedHashMap<String,Object>> listParse, String userId) {
- int successCount = 0;
- for (LinkedHashMap<String,Object> lhp : listParse) {
- /*
- 只对未督查过和督查中的水库进行批量填报
- */
- try {
- String rgstrId = MapUtils.getString(lhp,"rgstrId");
- if (StringUtils.isBlank(rgstrId) || rgstrId.length() != 32) {
- continue;
- }
- // 1.修改基础信息表和基础信息纠错表
- // 改成修改登记表
- this.insertOrUpdateSwhsRgstr(lhp,userId);
- // 2.安全保障达标落实情况
- this.insertOrUpdateSwhsRgstrSafety(lhp, userId);
- // 3.保护措施监管情况
- this.insertOrUpdateSwhsRgstrMeasures(lhp, userId);
- successCount ++;
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- int sumCount = listParse.size();
- return " 此次填报共:<b>" + sumCount + "</b>条," +
- " 成功<b>" + successCount + "</b>条,失败<b>"+ (sumCount - successCount) + "</b>条";
- }
- /**
- * 只入库一次,只取一次,取完及时删除
- */
- private List<LinkedHashMap<String,Object>> getParseDataByRedis(String cacheId){
- // 取出
- List<LinkedHashMap<String,Object>> listParse = redisTemplate.opsForList().range(cacheId, 0, -1);
- // 删除
- redisTemplate.delete(cacheId);
- return listParse;
- }
- /**
- * @see cn.com.goldenwater.dcproj.controller.BisInspSwhsRgstrController#insert(BisInspSwhsRgstr)
- */
- private void insertOrUpdateSwhsRgstr(LinkedHashMap<String,Object> lhp,String userId) throws InstantiationException, IllegalAccessException {
- BisInspSwhsRgstr bisInspSwhsRgstr = (BisInspSwhsRgstr) ExpAndImpUtil.convertMapToBean(BisInspSwhsRgstr.class, lhp);
- // 先用登记表id查一下
- BisInspSwhsRgstr rgstr = bisInspSwhsRgstrDao.get(MapUtils.getString(lhp,RGSTRID));
- bisInspSwhsRgstr.setId(rgstr.getId());
- bisInspSwhsRgstr.setObjId(rgstr.getObjId());
- bisInspSwhsRgstr.setSwhsId(rgstr.getSwhsId());
- bisInspSwhsRgstr.setUpTm(new Date());
- bisInspSwhsRgstr.setPersId(userId);
- bisInspSwhsRgstr.setGdX(rgstr.getGdX());
- bisInspSwhsRgstr.setGdY(rgstr.getGdY());
- bisInspSwhsRgstr.setGroupId(rgstr.getGroupId());
- if(StringUtils.isNotBlank(bisInspSwhsRgstr.getId())){
- bisInspSwhsRgstrService.updateRgstr(bisInspSwhsRgstr);
- }
- }
- /**
- * @see cn.com.goldenwater.dcproj.controller.AttSwhsBaseCrrctController#insert(AttSwhsBaseCrrct)
- */
- private void insertOrUpdateSwhsBaseCrrct(LinkedHashMap<String,Object> lhp,String userId){
- try{
- // 从导入的Excel里的字段赋值给实体类
- AttSwhsBaseCrrct attSwhsBaseCrrct = (AttSwhsBaseCrrct) ExpAndImpUtil.convertMapToBean(AttSwhsBaseCrrct.class, lhp);
- // 先用登记表id查一下
- BisInspSwhsRgstr rgstr = bisInspSwhsRgstrDao.get(MapUtils.getString(lhp,"rgstrId"));
- // 有没有纠错信息
- AttSwhsBaseCrrctParam param = new AttSwhsBaseCrrctParam();
- param.setSwhsCode(rgstr.getSwhsId());
- param.setPersId(userId);
- List<AttSwhsBaseCrrct> list = attSwhsBaseCrrctDao.findList(param);
- // 总是添加一条纠错到纠错表
- attSwhsBaseCrrct.setId(UuidUtil.uuid());
- attSwhsBaseCrrct.setPersId(userId);
- attSwhsBaseCrrct.setInTm(new Date());
- attSwhsBaseCrrct.setUpTm(new Date());
- attSwhsBaseCrrctDao.insert(attSwhsBaseCrrct);
- // 更新登记表
- BeanUtil.copyObject1(attSwhsBaseCrrct, rgstr);
- rgstr.setId(rgstr.getId());
- if(list.size() > 0){
- rgstr.setGdX(list.get(0).getSwhsLongGd());
- rgstr.setGdY(list.get(0).getSwhsLatGd());
- }
- rgstr.setCenterX(attSwhsBaseCrrct.getSwhsLong());
- rgstr.setCenterY(attSwhsBaseCrrct.getSwhsLat());
- rgstr.setPersId(userId);
- bisInspSwhsRgstrDao.update(rgstr);
- }catch (Exception e){
- e.printStackTrace();
- }
- }
- /**
- * @see cn.com.goldenwater.dcproj.controller.BisInspSwhsRgstrSafetyController#insert(BisInspSwhsRgstrSafety)
- */
- private void insertOrUpdateSwhsRgstrSafety(LinkedHashMap<String,Object> lhp,String userId) throws InstantiationException, IllegalAccessException {
- BisInspSwhsRgstrSafety bisInspSwhsRgstrSafety = (BisInspSwhsRgstrSafety) ExpAndImpUtil.convertMapToBean(BisInspSwhsRgstrSafety.class, lhp);
- // 新增或更新本表
- BisInspSwhsRgstrSafetyParam param = new BisInspSwhsRgstrSafetyParam();
- param.setRgstrId(bisInspSwhsRgstrSafety.getRgstrId());
- List<BisInspSwhsRgstrSafety> list = bisInspSwhsRgstrSafetyDao.findList(param);
- if (list.size() > 0 ){
- bisInspSwhsRgstrSafety.setId(list.get(0).getId());
- bisInspSwhsRgstrSafety.setUpTm(new Date());
- bisInspSwhsRgstrSafety.setRecPersId(userId);
- bisInspSwhsRgstrSafetyDao.update(bisInspSwhsRgstrSafety);
- }else {
- bisInspSwhsRgstrSafety.setInTm(new Date());
- bisInspSwhsRgstrSafety.setUpTm(new Date());
- bisInspSwhsRgstrSafety.setId(UuidUtil.uuid());
- bisInspSwhsRgstrSafety.setRecPersId(userId);
- bisInspSwhsRgstrSafetyDao.insert(bisInspSwhsRgstrSafety);
- }
- // 更新登记表
- if (org.apache.commons.lang3.StringUtils.isNotBlank(bisInspSwhsRgstrSafety.getRgstrId())) {
- BisInspSwhsRgstr rgstr = bisInspSwhsRgstrDao.get(bisInspSwhsRgstrSafety.getRgstrId());
- if (rgstr != null) {
- // 判断督查状态
- if(StringUtils.isNotBlank(bisInspSwhsRgstrSafety.getIsCoaeattsr().replace("0",""))
- && StringUtils.isNotBlank(bisInspSwhsRgstrSafety.getIsFrmsaisasdsam().replace("0",""))
- && StringUtils.isNotBlank(bisInspSwhsRgstrSafety.getIsWiqistcs().replace("0",""))
- && StringUtils.isNotBlank(bisInspSwhsRgstrSafety.getIsMcpacdar().replace("0",""))
- && StringUtils.isNotBlank(bisInspSwhsRgstrSafety.getIsWtpfilyeafrai().replace("0",""))
- ){
- // 已完成
- rgstr.setSafetyStat("2");
- }else{
- // 未完成
- rgstr.setSafetyStat("1");
- }
- rgstr.setState("2".equals(rgstr.getState()) ? "2" : "1");
- bisInspSwhsRgstrDao.update(rgstr);
- }
- }
- }
- /**
- * @see cn.com.goldenwater.dcproj.controller.BisInspSwhsRgstrMeasuresController#insert(BisInspSwhsRgstrMeasures)
- */
- private void insertOrUpdateSwhsRgstrMeasures(LinkedHashMap<String,Object> lhp,String userId) throws InstantiationException, IllegalAccessException {
- BisInspSwhsRgstrMeasures bisInspSwhsRgstrMeasures = (BisInspSwhsRgstrMeasures) ExpAndImpUtil.convertMapToBean(BisInspSwhsRgstrMeasures.class, lhp);
- // 更新本表
- BisInspSwhsRgstrMeasuresParam param = new BisInspSwhsRgstrMeasuresParam();
- param.setRgstrId(bisInspSwhsRgstrMeasures.getRgstrId());
- List<BisInspSwhsRgstrMeasures> list = bisInspSwhsRgstrMeasuresDao.findList(param);
- if (list.size() > 0 ){
- bisInspSwhsRgstrMeasures.setUpTm(new Date());
- bisInspSwhsRgstrMeasures.setId(list.get(0).getId());
- bisInspSwhsRgstrMeasures.setRecPersId(userId);
- bisInspSwhsRgstrMeasuresDao.update(bisInspSwhsRgstrMeasures);
- }else {
- bisInspSwhsRgstrMeasures.setInTm(new Date());
- bisInspSwhsRgstrMeasures.setUpTm(new Date());
- String uuid = UuidUtil.uuid();
- bisInspSwhsRgstrMeasures.setId(uuid);
- bisInspSwhsRgstrMeasures.setRecPersId(userId);
- bisInspSwhsRgstrMeasuresDao.insert(bisInspSwhsRgstrMeasures);
- }
- // 更新 登记表
- if (org.apache.commons.lang3.StringUtils.isNotBlank(bisInspSwhsRgstrMeasures.getRgstrId())) {
- BisInspSwhsRgstr rgstr = bisInspSwhsRgstrDao.get(bisInspSwhsRgstrMeasures.getRgstrId());
- if (rgstr != null) {
- // 判断督查状态
- if(StringUtils.isNotBlank(bisInspSwhsRgstrMeasures.getIsTcowqmWtmiafmtr().replace("0",""))
- && StringUtils.isNotBlank(bisInspSwhsRgstrMeasures.getIsEowqoms().replace("0",""))
- && StringUtils.isNotBlank(bisInspSwhsRgstrMeasures.getIsSwqiowstswrmisar().replace("0",""))
- && StringUtils.isNotBlank(bisInspSwhsRgstrMeasures.getIsAmwqiadtfad().replace("0",""))
- && StringUtils.isNotBlank(bisInspSwhsRgstrMeasures.getIsPzfdwsad().replace("0",""))
- && StringUtils.isNotBlank(bisInspSwhsRgstrMeasures.getIsEcgbacws().replace("0",""))
- && StringUtils.isNotBlank(bisInspSwhsRgstrMeasures.getIsHasProject().replace("0",""))
- && StringUtils.isNotBlank(bisInspSwhsRgstrMeasures.getIsHasIwba().replace("0",""))
- ){
- // 已完成
- rgstr.setMeasuresStat("2");
- }else{
- // 未完成
- rgstr.setMeasuresStat("1");
- }
- rgstr.setState("2".equals(rgstr.getState()) ? "2" : "1");
- bisInspSwhsRgstrDao.update(rgstr);
- }
- }
- }
- /**
- * 过滤掉findList不是此用户下的此节点的数据
- */
- private List<LinkedHashMap<String,Object>> filterNotTreeIdData(List<LinkedHashMap<String,Object>> listParse, String userId, String orgIds) {
- List<BisInspRgstrDto> rgstrList = this.getRgstrList(userId,orgIds);
- Object[] rgstrIds = rgstrList.stream().map(BisInspRgstrDto::getRgstrId).toArray();
- if (listParse == null) {
- return new ArrayList<>();
- } else {
- listParse = listParse.stream().filter(x -> ArrayUtils.contains(rgstrIds,MapUtils.getString(x,"rgstrId"))).collect(Collectors.toList());
- }
- return listParse;
- }
- private List<BisInspRgstrDto> getRgstrList(String userId,String orgIds){
- // 导出参数
- TypeParam typeParam = new TypeParam();
- typeParam.setpType("13");
- typeParam.setPresId(userId);
- // 0未督查 1督查中 2已督查
- typeParam.setState("1,0");
- typeParam.setGroupId(orgIds);
- return bisInspSwhsRgstrDao.findSwhsPage(typeParam);
- }
- }
|