|
1
2
|
package com.huaheng.pc.config.cycleCountPreference.service;
|
|
3
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
4
|
import com.huaheng.common.utils.Wrappers;
|
|
5
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
6
7
|
import com.huaheng.common.utils.security.ShiroUtils;
import com.huaheng.framework.web.domain.AjaxResult;
|
|
8
9
|
import com.huaheng.pc.config.cycleCountPreference.domain.CycleCountPreference;
import com.huaheng.pc.config.cycleCountPreference.mapper.CycleCountPreferenceMapper;
|
|
10
|
import org.springframework.stereotype.Service;
|
|
11
12
|
import org.springframework.transaction.annotation.Transactional;
|
|
13
|
import javax.annotation.Resource;
|
|
14
|
import java.text.SimpleDateFormat;
|
|
15
|
import java.util.Date;
|
|
16
|
import java.util.List;
|
|
17
|
|
|
18
|
@Service("cycleCountPreferenceService")
|
|
19
20
|
public class CycleCountPreferenceService extends ServiceImpl<CycleCountPreferenceMapper, CycleCountPreference> {
|
|
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
@Resource
private CycleCountPreferenceMapper cycleCountPreferenceMapper;
/**
* 页面查询盘点首选项接口
* */
public List<CycleCountPreference> selectCycleCountPreferenceList() {
LambdaQueryWrapper<CycleCountPreference> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper
.eq(CycleCountPreference::getWarehouseCode, ShiroUtils.getWarehouseCode())
.orderByDesc(CycleCountPreference::getId);
return this.list(lambdaQueryWrapper);
}
/**
* 页面展示名字
* */
public String selectCycleCountPreferenceName(String cycleCountPreferenceCode) {
String name = cycleCountPreferenceMapper.selectCycleCountPreferenceName(cycleCountPreferenceCode);
return name;
}
|
|
43
44
45
46
47
|
/**
*新增盘点首选项
* @param cycleCountPreference
* @return
*/
|
|
48
|
@Transactional(rollbackFor = Exception.class)
|
|
49
50
|
public AjaxResult addSave (CycleCountPreference cycleCountPreference){
|
|
51
|
cycleCountPreference.setCode(newCode());
|
|
52
53
54
55
56
57
58
59
60
|
cycleCountPreference.setWarehouseCode(ShiroUtils.getWarehouseCode());
cycleCountPreference.setCreatedBy(ShiroUtils.getLoginName());
cycleCountPreference.setCreated(new Date());
cycleCountPreference.setLastUpdatedBy(ShiroUtils.getLoginName());
this.save(cycleCountPreference);
return AjaxResult.success("新增完成!");
}
|
|
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
|
/**
* 自动生成盘点首选项Code
* 使用特定字段和ID组合成Code
*/
public String newCode(){
//先查询前一个ID生成当前的数字,再拼接
String code = null;
Date now = new Date();
SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
LambdaQueryWrapper<CycleCountPreference> lambda = Wrappers.lambdaQuery();
lambda.select(CycleCountPreference::getCode)
.orderByDesc(CycleCountPreference::getId).last("Limit 1");
// code = ccp + 日期 + (排序号 + 1)
String maxCode = null;
CycleCountPreference cycleCountPreference = this.getOne(lambda);
if ( cycleCountPreference != null){
maxCode = this.getOne(lambda).getCode();
}
if (maxCode != null && maxCode.substring(maxCode.length() - 13, maxCode.length() - 5).equals(df.format(now))) {
Integer Count = Integer.valueOf(maxCode.substring(maxCode.length() - 5 ));
code = "ccp" + df.format(now) + String.format("%05d", Count + 1);
} else {
code = "ccp" + df.format(now) +"00001";
}
return code;
}
|
|
88
89
90
91
92
93
94
|
/**
* 复制盘点首选项表
*
* @param warehouseCode 原仓库编码
* @param newWarehouseCode 新仓库编码
* @return 是否复制成功
*/
|
|
95
|
@Transactional(rollbackFor = Exception.class)
|
|
96
97
98
99
100
101
102
103
|
public boolean cycleCountPreferenceCopy(String warehouseCode, String newWarehouseCode) {
log.trace("开始复盘点首选项表");
LambdaQueryWrapper<CycleCountPreference> lambdaQueryWrapper = Wrappers.lambdaQuery();
lambdaQueryWrapper.eq(CycleCountPreference::getWarehouseCode, newWarehouseCode);
if (!this.list(lambdaQueryWrapper).isEmpty()){
log.error(newWarehouseCode+"仓库已存在");
return false;
}
|
|
104
105
|
lambdaQueryWrapper = Wrappers.lambdaQuery();
|
|
106
107
108
109
110
111
112
|
lambdaQueryWrapper.eq(CycleCountPreference::getWarehouseCode, warehouseCode);
List<CycleCountPreference> cycleCountPreferenceList = this.list(lambdaQueryWrapper);
for ( CycleCountPreference countPreference : cycleCountPreferenceList) {
countPreference.setId(null);
countPreference.setWarehouseCode(newWarehouseCode);
}
|
|
113
|
|
|
114
115
116
117
118
119
120
|
if ( this.saveBatch(cycleCountPreferenceList) ){
log.trace("复制盘点首选项表成功,新仓库编码是:"+newWarehouseCode);
return true;
} else {
return false;
}
}
|
|
121
122
|
|
|
123
124
125
126
127
128
|
|
|
129
|
}
|