From e4aed6ad69c6b4b55d6d043f3706967439e2500d Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期一, 04 九月 2023 15:40:13 +0800
Subject: [PATCH] 原材料检验修改9-4
---
inspect-server/src/main/java/com/yuanchu/mom/service/impl/RawInspectServiceImpl.java | 171 ++++++++++++++++++++++----------------------------------
1 files changed, 67 insertions(+), 104 deletions(-)
diff --git a/inspect-server/src/main/java/com/yuanchu/mom/service/impl/RawInspectServiceImpl.java b/inspect-server/src/main/java/com/yuanchu/mom/service/impl/RawInspectServiceImpl.java
index aa55ef8..b3e0e7b 100644
--- a/inspect-server/src/main/java/com/yuanchu/mom/service/impl/RawInspectServiceImpl.java
+++ b/inspect-server/src/main/java/com/yuanchu/mom/service/impl/RawInspectServiceImpl.java
@@ -2,8 +2,10 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanchu.mom.mapper.*;
import com.yuanchu.mom.pojo.*;
@@ -14,6 +16,7 @@
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.*;
@@ -25,8 +28,7 @@
* @createDate 2023-07-31 14:43:15
*/
@Service
-public class RawInspectServiceImpl extends ServiceImpl<RawInspectMapper, RawInspect>
- implements RawInspectService {
+public class RawInspectServiceImpl extends ServiceImpl<RawInspectMapper, RawInspect> implements RawInspectService {
@Resource
RawInspectMapper rawInspectMapper;
@@ -40,128 +42,89 @@
@Resource
InspectUnacceptedMapper inspectUnacceptedMapper;
- @Resource
- DeviceService deviceService;
- @Resource
- MaterialMapper materialMapper;
-
- @Resource
- UserService userService;
-
- @Resource
- SpecificationsService specificationsService;
-
- @Resource
- StandardService standardService;
-
- @Resource
- ProductMapper productMapper;
-
+ //鍒嗛〉鏌ヨ鍘熸潗鏂欐楠屽崟鍒楄〃
@Override
- public Map<String, Object> selectRawInspectsList(int pageSize, int countSize, String formTime, String createTime, int insState, int judgeState) {
- Map<String, Object> map = new HashMap<>();
- map.put("count", rawInspectMapper.selectCount(new QueryWrapper<RawInspect>().eq("state", 1)));
- map.put("data", rawInspectMapper.selectRawInspectsByLimit((pageSize - 1) * countSize, pageSize * countSize, formTime, createTime, insState, judgeState));
- return map;
+ public IPage<Map<String, Object>> selectRawInspectsList(Page<Object> page, String formTime, String code, Integer insState, String name) {
+ return rawInspectMapper.selectRawInspectsList(page, formTime, code, insState, name);
}
//鏍规嵁妫�楠屽崟id鏌ヨ鍘熸潗鏂欐楠屽崟璇︽儏
@Override
- public RawInspectVo selectRawInspectsListById(Integer id) {
- //灏嗘楠屽崟鍩烘湰淇℃伅鏌ヨ鍑烘潵骞跺皝瑁呭埌RawInspectVo瀵硅薄涓�
- RawInspect rawInspect = rawInspectMapper.selectById(id);
- RawInspectVo rawInspectVo = new RawInspectVo();
- BeanUtils.copyProperties(rawInspect, rawInspectVo);
- //鏌ヨ妫�楠屽崟閲岄潰鐨勬楠岄」鐩�,骞跺皝瑁呭埌RawInspectVo瀵硅薄涓�
- LambdaQueryWrapper<RawInsProduct> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(RawInsProduct::getRawInspectId, id);
- List<RawInsProduct> rawInsProducts = rawInsProductMapper.selectList(queryWrapper);
- //杩欓噷鏌ュ埌鐨勮澶噄d鍜屾楠屽憳id瑕佹煡璇㈠悕绉�
- List<RawInsProductVo> rawInsProductVos = rawInsProducts.stream().map(rawInsProduct -> {
- //灏嗕竴涓璞$殑鍊艰祴鍊肩粰鍙︿竴涓璞�
- RawInsProductVo rawInsProductVo = new RawInsProductVo();
- BeanUtils.copyProperties(rawInsProduct, rawInsProductVo);
- //鑾峰彇璁惧鍚�(鍓嶆彁鏄鏋滃瓨鍦�)
- if (rawInsProduct.getDeviceId() != null) {
- String deviceName = deviceService.getDeviceNameById(rawInsProduct.getDeviceId());
- rawInsProductVo.setDeviceName(deviceName);
- }
- //鑾峰彇鐢ㄦ埛鍚�(鍓嶆彁鏄鏋滃瓨鍦�)
- if (rawInsProduct.getUserId() != null) {
- String userName = userService.selectNameById(rawInsProduct.getUserId());
- rawInsProductVo.setUserName(userName);
- }
- return rawInsProductVo;
- }).collect(Collectors.toList());
- rawInspectVo.setRawInsProducts(rawInsProductVos);
- return rawInspectVo;
+ public List<Map<String, Object>> selectRawInspectsListById(Integer id) {
+ return rawInspectMapper.selectRawInspectsListById(id);
}
//鏇存柊妫�楠岀姸鎬�(涓婃姤)
@Override
- public boolean updateRawInspectsById(Integer id) {
- //鏇存柊妫�楠屽崟閲岄潰鐨勬楠岀姸鎬佸拰妫�楠岀粨璁�
- RawInspectVo rawInspectVo = selectRawInspectsListById(id);
- RawInspect rawInspect = RawInspect.builder()
- .id(id)
- .insState(1)
- .insTime(new Date())
- .judgeState(rawInspectVo.getJudgeState())
- .build();
- rawInspectMapper.updateById(rawInspect);
- //涓嶇妫�楠屽悎鏍间笌涓嶅悎鏍�,閮借鏂板鍒板師鏉愭枡搴撳瓨
-
- /* //濡傛灉妫�楠岀粨璁轰负涓嶅悎鏍�,鍒欓渶瑕佹柊澧炰笉鍚堟牸妫�楠屽崟
- if (rawInspectVo.getJudgeState() == 0) {
+ @Transactional(rollbackFor = Exception.class)
+ public String updateRawInspectsById(Integer id) {
+ /*鏇存柊妫�楠屽崟閲岄潰鐨勬楠岀粨璁�*/
+ //鍏堝垽鏂楠岀粨鏋�
+ List<Integer> results = rawInsProductMapper.getresult(id);
+ int count = 0;
+ for (Integer result : results) {
+ if (result != null && result == 1) {
+ count++;
+ }
+ }
+ RawInspect rawInspect = new RawInspect();
+ rawInspect.setId(id);
+ rawInspect.setInsState(1);
+ //濡傛灉妫�楠岄」鐩腑鐨勭粨璁哄寘鍚笉鍚堟牸鍒欐楠屽崟涓嶅悎鏍�
+ if (results.contains(0)) {
+ rawInspect.setJudgeState(0);
+ //鏇存柊妫�楠屽崟
+ rawInspectMapper.updateById(rawInspect);
+ } else if (count == results.size()) {
+ rawInspect.setJudgeState(1);
+ rawInspectMapper.updateById(rawInspect);
+ } else return "椤圭洰鏈楠屽畬!";
+ /*濡傛灉妫�楠岀粨璁轰负涓嶅悎鏍�,鍒欓渶瑕佹柊澧炰笉鍚堟牸妫�楠屽崟*/
+ if (rawInspect.getJudgeState() == 0) {
InspectUnaccepted rawUnaccepted = InspectUnaccepted.builder()
- .reason(rawInspectVo.getName() + "涓嶅悎鏍�") //鏆備笖瀹氫箟涓哄師鏉愭枡涓嶅悎鏍�
+ .reason(rawInspect.getName() + "涓嶅悎鏍�") //鏆備笖瀹氫箟涓哄師鏉愭枡涓嶅悎鏍�
.rawInspectId(id)
- .type(2) //绫诲瀷涓哄師鏉愭枡
+ .type(0) //绫诲瀷涓哄師鏉愭枡
.build();
inspectUnacceptedMapper.insert(rawUnaccepted);
- }*/
- return true;
+ }
+ return "涓婃姤鎴愬姛!";
}
- //鏂板妫�楠屽崟
+ //鏂板鍘熸潗鏂欐楠屽崟
@Override
- public Integer addRawInspects(String userName, RawInspect rawInspect) {
- rawInspect.setUserName(userName);
- //鏂板妫�楠屽崟
- rawInspectMapper.insert(rawInspect);
- //鑾峰彇鐗╂枡id
- Material material = materialMapper.selectOne(Wrappers.<Material>query()
- .eq("name", rawInspect.getName())
- .eq("code", rawInspect.getCode()));
- //鑾峰彇瑙勬牸鍚嶇О鍜屽瀷鍙峰悕绉�
- String specification = rawInspect.getSpecifications();
- String[] strings = specification.split("-");
- String stName = strings[0];//瑙勬牸鍚嶇О
- String spName = strings[1];//鍨嬪彿鍚嶇О
- //鑾峰彇瑙勬牸id
- Standard standard = standardService.getOne(Wrappers.<Standard>query()
- .eq("name", stName)
- .eq("material_id", material.getId()));
- //鑾峰彇鍨嬪彿id
- Specifications specifications = specificationsService.selectSpIdByname(standard.getId(), spName);
- //鏍规嵁鍨嬪彿id鏌ヨ椤圭洰淇℃伅
- List<Product> productList = productMapper.selectList(Wrappers.<Product>query().eq("specifications_id", specifications.getId()));
- ArrayList<RawInsProduct> list = new ArrayList<>();
- for (Product product : productList) {
- RawInsProduct rawInsProduct = RawInsProduct.builder()
- .name(product.getName())
- .unit(product.getUnit())
- .required(product.getRequired())
- .internal(product.getInternal())
- .rawInspectId(rawInspect.getId())
- .build();
- list.add(rawInsProduct);
+ @Transactional(rollbackFor = Exception.class)
+ public String addRawInspects(String userName, RawInspectVo rawInspectVo) {
+ //鎶ユ浜�(鏂板妫�楠屽崟鐨勪汉)
+ rawInspectVo.setUserName(userName);
+ //鏍¢獙鏍囧噯鍊�,鍐呮帶鍊兼牸寮�
+ List<RawInsProductVo> rawInsProductVos = rawInspectVo.getRawInsProducts();
+ for (RawInsProductVo rawInsProductVo : rawInsProductVos) {
+ char internal = rawInsProductVo.getInternal().charAt(0);
+ char required = rawInsProductVo.getRequired().charAt(0);
+ if (internal != '>' && internal != '<' && internal != '=') {
+ if (required != '>' && required != '<' && required != '=') {
+ return "鏍囧噯鍊艰緭鍏ユ牸寮忔湁闂!";
+ }
+ return "鍐呮帶鍊艰緭鍏ユ牸寮忔湁闂!";
+ }
}
+ /*鏂板鍘熸潗鏂欐楠屽崟*/
+ RawInspect rawInspect = new RawInspect();
+ BeanUtils.copyProperties(rawInspectVo, rawInspect);
+ rawInspectMapper.insert(rawInspect);
+ /*鏂板鍘熸潗鏂欐楠岄」鐩崟*/
+ List<RawInsProduct> rawInsProductList = rawInsProductVos.stream().map(rawInsProVo -> {
+ RawInsProduct rawInsProduct = new RawInsProduct();
+ BeanUtils.copyProperties(rawInsProVo, rawInsProduct);
+ rawInsProduct.setRawInspectId(rawInspect.getId());
+ return rawInsProduct;
+ }).collect(Collectors.toList());
//妫�楠岄」鐩壒閲忔坊鍔�
- rawInsProductService.saveBatch(list);
- return rawInspect.getId();
+ rawInsProductService.saveBatch(rawInsProductList);
+ return "鏂板妫�楠屽崟鎴愬姛!";
}
}
--
Gitblit v1.9.3