MaterialServiceImpl.java
4.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package com.huaheng.pc.config.material.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.huaheng.common.exception.BusinessException;
import com.huaheng.common.support.Convert;
import com.huaheng.common.utils.StringUtils;
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
import com.huaheng.pc.receipt.receiptDetail.domain.ReceiptDetail;
import com.huaheng.pc.receipt.receiptDetail.service.ReceiptDetailService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaheng.pc.config.material.mapper.MaterialMapper;
import com.huaheng.pc.config.material.domain.Material;
@Service
public class MaterialServiceImpl extends ServiceImpl<MaterialMapper, Material> implements MaterialService{
@Resource
private ReceiptDetailService receiptDetailService;
@Override
public AjaxResult removeByIds(String ids) {
int count = 0;
for (Integer id : Convert.toIntArray(ids)) {
Material material = this.getById(id);
LambdaQueryWrapper<ReceiptDetail> lambda = Wrappers.lambdaQuery();
lambda.eq(ReceiptDetail::getWarehouseCode, ShiroUtils.getWarehouseCode())
.eq(ReceiptDetail::getMaterialCode, material.getCode())
.eq(ReceiptDetail::getDeleted, false)
.last("LIMIT 1");
Map<String, Object> map = receiptDetailService.getMap(lambda);
if (map != null) {
return AjaxResult.error("存货编码(" + material.getCode() +")存在入库单,不能删除!");
}
material.setDeleted(true);
material.setLastUpdatedBy(ShiroUtils.getLoginName());
if (this.updateById(material)){
count++;
}
}
return AjaxResult.success("成功删除"+count+"条记录");
}
/**
* 导入物料数据
*
* @param materialList 用户数据列表
* @param operName 操作用户
* @return 结果
*/
@Override
public String importMaterial(List<Material> materialList, Boolean isUpdateSupport, String operName) {
if (StringUtils.isNull(materialList) || materialList.size() == 0) {
throw new BusinessException("导入数据不能为空!");
}
int successNum = 0;
int failureNum = 0;
StringBuilder successMsg = new StringBuilder();
StringBuilder failureMsg = new StringBuilder();
for (Material material : materialList) {
try {
LambdaQueryWrapper<Material> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(Material::getCode, material.getCode());
// 验证是否存在这个用户
Material m = this.getOne(lambdaQueryWrapper);
if (StringUtils.isNull(m)) {
System.out.println(ShiroUtils.getLoginName());
material.setCreatedBy(ShiroUtils.getUser().getLoginName());
material.setLastUpdatedBy(ShiroUtils.getLoginName());
this.save(material);
successNum++;
successMsg.append("<br/>" + successNum + "、编码 " + material.getCode() + " 导入成功");
}
} catch (Exception e) {
failureNum++;
String msg = "<br/>" + failureNum + "、编码" + material.getCode() + " 导入失败:";
failureMsg.append(msg + e.getMessage());
log.error(msg, e);
}
}
if (failureNum > 0) {
failureMsg.insert(0, "很抱歉,导入失败!共 " + failureNum + " 条数据格式不正确,错误如下:");
throw new BusinessException(failureMsg.toString());
} else {
successMsg.insert(0, "恭喜您,数据已全部导入成功!共 " + successNum + " 条,数据如下:");
}
return successMsg.toString();
}
}