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.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.example.erp.entity.pp.PatchLog; |
| | | import com.example.erp.entity.pp.ReportingWork; |
| | | import com.example.erp.entity.userInfo.SysError; |
| | | import com.example.erp.mapper.pp.PatchLogMapper; |
| | | import com.example.erp.mapper.pp.ReportingWorkMapper; |
| | | import com.example.erp.service.userInfo.SysErrorService; |
| | | 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 ReplenishService { |
| | | final |
| | | PatchLogMapper patchMapper; |
| | | |
| | | final |
| | | SysErrorService sysErrorService; |
| | | |
| | | final |
| | | ReportingWorkMapper reportingWorkMapper; |
| | | |
| | | public ReplenishService(PatchLogMapper patchMapper, SysErrorService sysErrorService, ReportingWorkMapper reportingWorkMapper) { |
| | | this.patchMapper = patchMapper; |
| | | this.sysErrorService = sysErrorService; |
| | | this.reportingWorkMapper = reportingWorkMapper; |
| | | } |
| | | |
| | | |
| | | public List<Map<String, Object>> getSelectReplenish(Integer pageNum, Integer pageSize) { |
| | | Integer offset = (pageNum - 1) * pageSize; |
| | | return patchMapper.getSelectReplenish(offset,pageSize); |
| | | |
| | | } |
| | | |
| | | public Map<String, Object> SelectReplenish(Integer pageNum, Integer pageSize,List<String> selectDate,PatchLog patchLog) { |
| | | 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",patchMapper.SelectReplenish(offset,pageSize,startDate,endDate,patchLog)); |
| | | map.put("total",patchMapper.SelectReplenishPageTotal(offset,pageSize,startDate,endDate,patchLog)); |
| | | |
| | | List<String> list = new ArrayList<>(); |
| | | list.add(startDate); |
| | | list.add(endDate); |
| | | map.put("selectDate",list); |
| | | return map; |
| | | } |
| | | |
| | | public Boolean saveReplenish(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<PatchLog> patchLoglist = JSONArray.parseArray(JSONObject.toJSONString(object.get("patchLog")), PatchLog.class); |
| | | if (!patchLoglist.isEmpty()){ |
| | | for (PatchLog patchLog : patchLoglist) { |
| | | //添加返工记录,修改次破明细数量 |
| | | patchMapper.insertReplenish(patchLog,oddNumber); |
| | | patchMapper.updateDamageDetails(patchLog); |
| | | } |
| | | } |
| | | |
| | | } 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 updateReplenish(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(); |
| | | } |
| | | //获取对象集合循环进行新增修改 |
| | | List<PatchLog> patchLoglist = JSONArray.parseArray(JSONObject.toJSONString(object.get("patchLog")), PatchLog.class); |
| | | if (!patchLoglist.isEmpty()){ |
| | | for (PatchLog patchLog : patchLoglist) { |
| | | //审核 |
| | | patchMapper.updateReplenish(patchLog,userName); |
| | | ReportingWork reportingWork = reportingWorkMapper |
| | | .selectOne(new QueryWrapper<ReportingWork>().eq("reporting_work_id",patchLog.getReportingWorkId())); |
| | | //修改小片流程卡数量 |
| | | patchMapper.updateOrderProcessDetail(patchLog,reportingWork); |
| | | } |
| | | } |
| | | |
| | | } 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 String orderNumberSetting(String type) { |
| | | //根据类型自动生成不同的操作单号 |
| | | String alias=""; |
| | | if(Objects.equals(type, "补片")){ |
| | | alias="BP"; |
| | | } |
| | | //查询当天的最大数量 |
| | | Integer maximum=patchMapper.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; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |