New file |
| | |
| | | package com.example.erp.service.pp; |
| | | |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.dynamic.datasource.annotation.DS; |
| | | import com.example.erp.dto.pp.ReworkDTO; |
| | | import com.example.erp.entity.pp.BasicDataProduce; |
| | | import com.example.erp.entity.pp.FlowCard; |
| | | import com.example.erp.entity.pp.PatchLog; |
| | | import com.example.erp.entity.pp.Rework; |
| | | import com.example.erp.entity.userInfo.Log; |
| | | import com.example.erp.entity.userInfo.SysError; |
| | | import com.example.erp.mapper.pp.*; |
| | | import com.example.erp.service.userInfo.LogService; |
| | | import com.example.erp.service.userInfo.SysErrorService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.transaction.interceptor.TransactionAspectSupport; |
| | | import com.example.erp.mapper.pp.FlowCardMapper; |
| | | |
| | | import java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.util.*; |
| | | |
| | | |
| | | @Service |
| | | @DS("pp") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public class ReworkService { |
| | | @Autowired |
| | | PatchLogMapper patchMapper; |
| | | @Autowired |
| | | ReworkMapper reworkMapper; |
| | | @Autowired |
| | | BasicDateProduceMapper basicDateProduceMapper; |
| | | @Autowired |
| | | SysErrorService sysErrorService; |
| | | |
| | | final |
| | | FlowCardMapper flowCardMapper; |
| | | |
| | | final LogService logService; |
| | | |
| | | public ReworkService(FlowCardMapper flowCardMapper,LogService logService) { |
| | | |
| | | this.flowCardMapper = flowCardMapper; |
| | | this.logService = logService; |
| | | } |
| | | |
| | | public List<Map<String, Object>> getSelectRework(Integer pageNum, Integer pageSize) { |
| | | Integer offset = (pageNum - 1) * pageSize; |
| | | Map<String, Object> map = new HashMap<>(); |
| | | List<Map<String, Object>> listMap = new ArrayList<>(); |
| | | |
| | | |
| | | List<Map<String, Object>> ReworkMap = reworkMapper.getSelectRework(offset, pageSize); |
| | | |
| | | |
| | | for (Map<String, Object> item : ReworkMap) { |
| | | item.put("reworkTeam", ""); |
| | | List<BasicDataProduce> basicCategory = new ArrayList<>(); |
| | | List<BasicDataProduce> basicDataProduceList = basicDateProduceMapper.SelectWorkBasicTeams(item.get("reworkProcesses").toString()); |
| | | for (BasicDataProduce basicDataProduce : basicDataProduceList) { |
| | | if (Objects.equals(basicDataProduce.getBasicData().getBasicName(), item.get("reworkProcesses"))) { |
| | | basicCategory.add(basicDataProduce); |
| | | } |
| | | } |
| | | item.put("basicCategory", basicCategory); |
| | | listMap.add(item); |
| | | } |
| | | return listMap; |
| | | } |
| | | |
| | | public Map<String, Object> SelectRework(Integer pageNum, Integer pageSize, List<String> selectDate, ReworkDTO rework) { |
| | | Integer offset = (pageNum - 1) * pageSize; |
| | | String endDate = LocalDate.now().toString(); |
| | | String startDate = LocalDate.now().minusDays(15).toString(); |
| | | if (selectDate != null && selectDate.size() == 2) { |
| | | if (!selectDate.get(0).isEmpty()) { |
| | | startDate = selectDate.get(0); |
| | | } |
| | | if (!selectDate.get(1).isEmpty()) { |
| | | endDate = selectDate.get(1); |
| | | } |
| | | } |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("data", reworkMapper.SelectRework(offset, pageSize, startDate, endDate, rework)); |
| | | map.put("total", reworkMapper.SelectReworkPageTotal(offset, pageSize, startDate, endDate, rework)); |
| | | |
| | | List<String> list = new ArrayList<>(); |
| | | list.add(startDate); |
| | | list.add(endDate); |
| | | map.put("selectDate", list); |
| | | return map; |
| | | } |
| | | |
| | | public Boolean saveRework(Map<String, Object> object) { |
| | | boolean saveState = true; |
| | | Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint(); |
| | | try { |
| | | String userName = ""; |
| | | String userId = ""; |
| | | if (object.get("userName") != null) { |
| | | userName = object.get("userName").toString(); |
| | | } |
| | | if (object.get("userId") != null) { |
| | | userId = object.get("userId").toString(); |
| | | } |
| | | //获取单号 |
| | | String oddNumber = orderNumberSetting("返工"); |
| | | //获取对象集合循环进行新增修改 |
| | | List<Rework> reworklist = JSONArray.parseArray(JSONObject.toJSONString(object.get("rework")), Rework.class); |
| | | if (!reworklist.isEmpty()) { |
| | | for (Rework rework : reworklist) { |
| | | //添加返工记录,修改次破明细数量 |
| | | reworkMapper.insertRework(rework, oddNumber); |
| | | reworkMapper.updateDamageDetails(rework); |
| | | patchMapper.updateReportingWorkDetail(rework.getReportingWorkId(), Integer.valueOf(rework.getOrderSort()), rework.getTechnologyNumber()); |
| | | } |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint); |
| | | //将异常传入数据库 |
| | | SysError sysError = new SysError(); |
| | | sysError.setError(e.toString()); |
| | | sysError.setFunc("saveOrder"); |
| | | sysErrorService.insert(sysError); |
| | | saveState = false; |
| | | |
| | | } |
| | | //保存日志 |
| | | Log log = new Log(); |
| | | log.setContent(object.toString()); |
| | | log.setFunction("saveRework返工新增"); |
| | | log.setOperatorId((String) object.get("userId")); |
| | | log.setOperator((String) object.get("userName")); |
| | | logService.saveLog(log); |
| | | return saveState; |
| | | |
| | | } |
| | | |
| | | public Boolean updateRework(Map<String, Object> object) { |
| | | boolean saveState = true; |
| | | |
| | | String userName = ""; |
| | | String userId = ""; |
| | | if (object.get("userName") != null) { |
| | | userName = object.get("userName").toString(); |
| | | } |
| | | if (object.get("userId") != null) { |
| | | userId = object.get("userId").toString(); |
| | | } |
| | | //获取对象集合循环进行新增修改 |
| | | List<Rework> reworklist = JSONArray.parseArray(JSONObject.toJSONString(object.get("rework")), Rework.class); |
| | | if (!reworklist.isEmpty()) { |
| | | for (Rework rework : reworklist) { |
| | | //审核 |
| | | reworkMapper.updateRework(rework, userName); |
| | | } |
| | | } |
| | | |
| | | //保存日志 |
| | | Log log = new Log(); |
| | | log.setContent(object.toString()); |
| | | log.setFunction("updateRework返工审核"); |
| | | log.setOperatorId((String) object.get("userId")); |
| | | log.setOperator((String) object.get("userName")); |
| | | logService.saveLog(log); |
| | | return saveState; |
| | | |
| | | } |
| | | |
| | | public String orderNumberSetting(String type) { |
| | | //根据类型自动生成不同的操作单号 |
| | | String alias = ""; |
| | | if (Objects.equals(type, "返工")) { |
| | | alias = "FG"; |
| | | } |
| | | //查询当天的最大数量 |
| | | Integer maximum = reworkMapper.getMaximum(); |
| | | //设置两位不够补0 |
| | | String formattedNumber = String.format("%02d", maximum + 1); |
| | | //格式化当前日期 |
| | | Date currentDate = new Date(); |
| | | SimpleDateFormat dateFormat = new SimpleDateFormat("yyMMdd"); |
| | | String formattedDate = dateFormat.format(currentDate); |
| | | String oddNumbers = alias + formattedDate + formattedNumber; |
| | | return oddNumbers; |
| | | } |
| | | |
| | | public Object selectPrintSv(java.sql.Date selectTime1, java.sql.Date selectTime2, FlowCard flowCard) { |
| | | Map<String, Object> map = new HashMap<>(); |
| | | map.put("data", flowCardMapper.selectReworkPrintMp(selectTime1, selectTime2, flowCard)); |
| | | map.put("type", flowCardMapper.selectType()); |
| | | return map; |
| | | } |
| | | |
| | | public Boolean deleteReworkSv(Map<String, Object> object) { |
| | | boolean saveState = true; |
| | | Object savePoint = TransactionAspectSupport.currentTransactionStatus().createSavepoint(); |
| | | try { |
| | | //获取对象集合循环进行新增修改 |
| | | List<Rework> reworklist = JSONArray.parseArray(JSONObject.toJSONString(object.get("rework")), Rework.class); |
| | | if (!reworklist.isEmpty()){ |
| | | for (Rework rework : reworklist) { |
| | | //删除返工表对应补片id数据 |
| | | reworkMapper.deleteReworkMp(rework.getReworkId()); |
| | | //修改次破明细表补片数量和状态 |
| | | reworkMapper.updateReworkDdMp(rework.getReportingWorkId(),rework.getOrderSort(),rework.getTechnologyNumber(),rework.getReworkNum()); |
| | | //修改报工明细表状态 |
| | | reworkMapper.updateReworkBgMp(rework.getReportingWorkId(),rework.getOrderSort(),rework.getTechnologyNumber()); |
| | | |
| | | } |
| | | } |
| | | |
| | | } catch (Exception e) { |
| | | TransactionAspectSupport.currentTransactionStatus().rollbackToSavepoint(savePoint); |
| | | //将异常传入数据库 |
| | | SysError sysError = new SysError(); |
| | | sysError.setError(e.toString()); |
| | | sysError.setFunc("saveOrder"); |
| | | sysErrorService.insert(sysError); |
| | | saveState = false; |
| | | |
| | | } |
| | | |
| | | return saveState; |
| | | } |
| | | } |
| | | |