package com.thhy.materials.modules.biz.pipeout.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.github.pagehelper.util.StringUtil; import com.thhy.general.common.BasicResult; import com.thhy.general.common.enums.ProListenType; import com.thhy.general.config.SysUserInfo; import com.thhy.general.utils.ScreenMqUtils; import com.thhy.general.utils.UserInfoUtils; import com.thhy.materials.modules.biz.pipeout.entity.TPipeInfo; import com.thhy.materials.modules.biz.pipeout.entity.TPipeOut; import com.thhy.materials.modules.biz.pipeout.entity.TPipeOutPath; import com.thhy.materials.modules.biz.pipeout.entity.TPipeOutPosition; import com.thhy.materials.modules.biz.pipeout.entity.dto.PipeInfoDto; import com.thhy.materials.modules.biz.pipeout.entity.dto.ProjectSizeDto; import com.thhy.materials.modules.biz.pipeout.entity.dto.RanKingDto; import com.thhy.materials.modules.biz.pipeout.mapper.TPipeOutMapper; import com.thhy.materials.modules.biz.pipeout.service.TPipeOutService; import com.thhy.materials.modules.biz.service.FileService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; @Service public class TPipeOutServiceImpl implements TPipeOutService { @Resource private TPipeOutMapper pipeOutMapper; @Resource private FileService fileService; @Autowired private ScreenMqUtils screenMqUtils; @Override @Transactional public BasicResult pipeOutInsert(Map values) { SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo(); String userId = sysUserInfo.getUserId(); Date date1 = new Date(); SimpleDateFormat format2 = new SimpleDateFormat("yyyyMMdd"); String format3 = format2.format(date1); String pipe_out_number = pipeOutMapper.pipeOutNew(sysUserInfo.getCompanyId(),format3); if(!StringUtil.isEmpty(pipe_out_number)){ String substring = pipe_out_number.substring(pipe_out_number.length() - 4, pipe_out_number.length()); Integer integer = Integer.valueOf(substring); int i1 = (integer + 1); if(integer<10){ values.put("pipeOutNumber","F"+format3+"000"+i1); }else if(integer<100){ values.put("pipeOutNumber","F"+format3+"00"+i1); }else if(integer<1000){ values.put("pipeOutNumber","F"+format3+"0"+i1); }else if(integer<10000){ values.put("pipeOutNumber","F"+format3+""+i1); } }else { values.put("pipeOutNumber","F"+format3+"0001"); } values.put("pipeOutId",""); values.put("outUserId",userId); values.put("companyId",sysUserInfo.getCompanyId()); pipeOutMapper.pipeOutInsert(values); List pipeIds = (List) values.get("pipeIds"); Date date = new Date(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String format1 = format.format(date); if(pipeIds!=null && pipeIds.size()>0){ String pipeOutId = values.get("pipeOutId").toString(); for (String pipeId : pipeIds){ HashMap hashMap = new HashMap<>(); hashMap.put("pipeOutId",pipeOutId); hashMap.put("pipeId",pipeId); hashMap.put("id",""); pipeOutMapper.pipeOutPipeInsert(hashMap); pipeOutMapper.pipeInfoUpdate(pipeId,format1); //更新入库 String pipeNum = pipeOutMapper.queryPipeNumByPipeId(pipeId); pipeOutMapper.updateRepoRecord(pipeNum); } screenMqUtils.send(ProListenType.SENDINFO); } return BasicResult.success("出库成功"); } @Override public BasicResult pipeOutList(Map values) { SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo(); String companyId = sysUserInfo.getCompanyId(); values.put("companyId",companyId); Integer pageSize = Integer.valueOf(values.get("pageSize").toString()); Integer pageNum = Integer.valueOf(values.get("pageNum").toString()); PageHelper.startPage(pageNum,pageSize); List pipeOuts = pipeOutMapper.pipeOutList(values); PageInfo tPipeOutPageInfo = new PageInfo<>(pipeOuts); return BasicResult.success(tPipeOutPageInfo); } @Override public BasicResult pipeOutInfo(String pipeOutId) { TPipeOut pipeOut = pipeOutMapper.pipeOutInfo(pipeOutId); List tPipeInfo = pipeOutMapper.pipeOutPipeInfo(pipeOut.getPipeOutId()); pipeOut.setPipeInfos(tPipeInfo); return BasicResult.success(pipeOut); } @Override @Transactional public BasicResult pipeOutDel(String pipeOutId) { //查询已出库的 管片id List pipeIds = pipeOutMapper.pipeSelectPipeId(pipeOutId); if(pipeIds!=null&& pipeIds.size()>0){ for (String pipeId:pipeIds){ pipeOutMapper.pipeInfoUpIn(pipeId); } } pipeOutMapper.pipeOutPipeDel(pipeOutId); pipeOutMapper.pipeOutDel(pipeOutId); return BasicResult.success("删除成功"); } @Override public BasicResult pipeOutUpdate(Map values) { String pipeOutId = values.get("pipeOutId").toString(); //查询已出库的 管片id List pipeIds = pipeOutMapper.pipeSelectPipeId(pipeOutId); if(pipeIds!=null&& pipeIds.size()>0){ for (String pipeId:pipeIds){ pipeOutMapper.pipeInfoUpIn(pipeId); } } pipeOutMapper.pipeOutPipeDel(pipeOutId); List pipeIdss = (List) values.get("pipeIds"); Date date = new Date(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String format1 = format.format(date); if(pipeIdss!=null && pipeIdss.size()>0){ for (String pipeId : pipeIdss){ HashMap hashMap = new HashMap<>(); hashMap.put("pipeOutId",pipeOutId); hashMap.put("pipeId",pipeId); hashMap.put("id",""); pipeOutMapper.pipeOutPipeInsert(hashMap); pipeOutMapper.pipeInfoUpdate(pipeId,format1); } } pipeOutMapper.pipeOutUpdate(values); return BasicResult.success("修改成功"); } @Override public BasicResult pipeOutCheck(Map values) { String pipeNum = values.get("pipeNum").toString(); int length = pipeNum.length(); String substring = pipeNum.substring(0, 1); if(!substring.equals("P")||length!=17){ return BasicResult.faild("11111","编号有误","error"); } String p = pipeOutMapper.pipeOutCheck(pipeNum); if(!StringUtil.isEmpty(p)&&p.equals("1")){ return BasicResult.success(); }else if (!StringUtil.isEmpty(p)&&p.equals("0")){ return BasicResult.faild("11111","该管片未入库","error"); }else { return BasicResult.faild("11111","该管片已出库","error"); } } @Override public BasicResult pipeInfo(String pipeNum) { TPipeInfo tPipeInfo = pipeOutMapper.pipeInfo(pipeNum); int length = pipeNum.length(); String substring = pipeNum.substring(0, 1); if(!substring.equals("P")||length!=17){ return BasicResult.faild("11111","编号有误","error"); } String p = pipeOutMapper.pipeOutCheck(pipeNum); if(!StringUtil.isEmpty(p)&&p.equals("1")){ // return BasicResult.success(); return BasicResult.success(tPipeInfo); }else if (!StringUtil.isEmpty(p)&&p.equals("0")){ return BasicResult.faild("11111","该管片未入库","error"); }else { return BasicResult.faild("11111","该管片已出库","error"); } } @Override public BasicResult pipeOutShippingSum(Map values) { SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo(); String companyId = sysUserInfo.getCompanyId(); values.put("companyId",companyId); //累计发运总量 String shipping = pipeOutMapper.pipeOutShippingSum(values); //累计运输总量 String transport = pipeOutMapper.pipeOutTransportSum(values); //累计运输车次 String carNum = pipeOutMapper.pipeOutCarSum(values); //生产数量 String produce = pipeOutMapper.pipeOutProduceSum(values); HashMap hashMap = new HashMap<>(); hashMap.put("shipping",shipping); hashMap.put("transport",transport); hashMap.put("carNum",carNum); hashMap.put("produce",produce); return BasicResult.success(hashMap); } @Override public BasicResult pipeOutRanking(Map values) { SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo(); String companyId = sysUserInfo.getCompanyId(); values.put("companyId",companyId); List projectSizeDtos = pipeOutMapper.projectSize(values); if(projectSizeDtos!=null && projectSizeDtos.size()>0){ for (ProjectSizeDto projectSizeDto : projectSizeDtos){ values.put("proId",projectSizeDto.getProId()); values.put("sizes",projectSizeDto.getSizes()); List ranKingDtos = pipeOutMapper.pipeOutRanking(values); projectSizeDto.setRanKingDtos(ranKingDtos); } } return BasicResult.success(projectSizeDtos); } @Override public BasicResult pipeOutGps(Map values) { //出库管理 String pipeOutId = values.get("pipeOutId").toString(); List outPositions = pipeOutMapper.pipeOutGps(pipeOutId); return BasicResult.success(outPositions); } @Override public BasicResult pipeOutImg(Map values) { //图片 List files = (List) values.get("files"); //出库id String pipeOutId = values.get("pipeOutId").toString(); pipeOutMapper.pipeOutImgDel(pipeOutId); for (String file :files){ HashMap hashMap = new HashMap<>(); hashMap.put("pipeOutId",pipeOutId); hashMap.put("outPath",file); hashMap.put("id",""); pipeOutMapper.pipePathInsert(hashMap); } return BasicResult.success("上传成功"); } @Override public BasicResult pipeOutImgInfo(Map values) { List pipeOutPaths = pipeOutMapper.pipeOutImgInfo(values.get("pipeOutId").toString()); pipeOutPaths.stream().forEach(fl->{ JSONObject json = new JSONObject(); json.put("fullpath",fl.getOutPath()); BasicResult basicResult = fileService.fileinfo(json.toJSONString()); if(basicResult.isSuccess()){ JSONArray jsonArray = JSONArray.parseArray(basicResult.getData().toString()); for(Object obj : jsonArray){ JSONObject j = JSON.parseObject(obj.toString()); if(j.containsKey("name")&&"name".equals(j.getString("name"))){ fl.setOutPathName(j.getString("value")); } } } }); return BasicResult.success(pipeOutPaths); } @Override public BasicResult pipeInfoInList(Map values) { SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo(); String companyId = sysUserInfo.getCompanyId(); values.put("companyId",companyId); List pipeInfoDtos = pipeOutMapper.pipeInfoInList(values); return BasicResult.success(pipeInfoDtos); } }