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.entity.pp.BasicDataProduce; |
| | | import com.example.erp.entity.pp.PatchLog; |
| | | import com.example.erp.entity.pp.Rework; |
| | | import com.example.erp.entity.sd.Delivery; |
| | | import com.example.erp.entity.sd.OrderDetail; |
| | | import com.example.erp.entity.userInfo.SysError; |
| | | import com.example.erp.mapper.pp.BasicDateProduceMapper; |
| | | import com.example.erp.mapper.pp.ReworkMapper; |
| | | 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 java.text.SimpleDateFormat; |
| | | import java.time.LocalDate; |
| | | import java.util.*; |
| | | |
| | | |
| | | @Service |
| | | @DS("pp") |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public class ReworkService { |
| | | @Autowired |
| | | ReworkMapper reworkMapper; |
| | | @Autowired |
| | | BasicDateProduceMapper basicDateProduceMapper; |
| | | @Autowired |
| | | SysErrorService sysErrorService; |
| | | |
| | | |
| | | 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,Rework 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); |
| | | } |
| | | } |
| | | |
| | | } 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; |
| | | |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | |
| | | 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; |
| | | } |
| | | } |
| | | |