Browse Source

[feat] 委外加工

修改委外工序的新增后端接口,使用redis自动生成委外工序ID
新增自动生成委外工序编号后端接口
dev
liuxiaoxu 4 months ago
parent
commit
735c6ad134
  1. 12
      ruoyi-admin/src/main/java/com/ruoyi/system/controller/OutsourceProcessController.java
  2. 7
      ruoyi-admin/src/main/java/com/ruoyi/system/service/IOutsourceProcessService.java
  3. 58
      ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/OutsourceProcessServiceImpl.java
  4. 54
      ruoyi-admin/src/main/resources/templates/system/outsource_process/add.html

12
ruoyi-admin/src/main/java/com/ruoyi/system/controller/OutsourceProcessController.java

@ -150,4 +150,16 @@ public class OutsourceProcessController extends BaseController
{ {
return toAjax(outsourceProcessService.deleteOutsourceProcessByOutsourceProcessIds(ids)); return toAjax(outsourceProcessService.deleteOutsourceProcessByOutsourceProcessIds(ids));
} }
/**
* 自动生成委外工序编号
*
*/
@GetMapping("/generateOutsourceProcessNo")
@ResponseBody
public String generateOutsourceProcessNo(){
String result = outsourceProcessService.generateOutsourceProcessNo();
return result;
}
} }

7
ruoyi-admin/src/main/java/com/ruoyi/system/service/IOutsourceProcessService.java

@ -36,6 +36,13 @@ public interface IOutsourceProcessService
*/ */
public List<OutsourceProcess> selectOutsourceProcessList(OutsourceProcess outsourceProcess); public List<OutsourceProcess> selectOutsourceProcessList(OutsourceProcess outsourceProcess);
/**
* 自动生成委外工序编号
*
*/
public String generateOutsourceProcessNo();
/** /**
* 新增委外工序 * 新增委外工序
* *

58
ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/OutsourceProcessServiceImpl.java

@ -4,7 +4,10 @@ import java.text.DecimalFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.common.utils.StringUtils; import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.OutsourceProcess; import com.ruoyi.system.domain.OutsourceProcess;
import com.ruoyi.system.mapper.OutsourceProcessMapper; import com.ruoyi.system.mapper.OutsourceProcessMapper;
@ -12,6 +15,7 @@ import com.ruoyi.system.service.IOutsourceProcessService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.ruoyi.common.core.text.Convert; import com.ruoyi.common.core.text.Convert;
import org.springframework.transaction.annotation.Transactional;
/** /**
* 委外工序Service业务层处理 * 委外工序Service业务层处理
@ -25,6 +29,9 @@ public class OutsourceProcessServiceImpl implements IOutsourceProcessService
@Autowired @Autowired
private OutsourceProcessMapper outsourceProcessMapper; private OutsourceProcessMapper outsourceProcessMapper;
@Autowired
private RedisCache redisCache;
/** /**
* 查询委外工序 * 查询委外工序
* *
@ -55,55 +62,36 @@ public class OutsourceProcessServiceImpl implements IOutsourceProcessService
return outsourceProcessMapper.selectOutsourceProcessList(outsourceProcess); return outsourceProcessMapper.selectOutsourceProcessList(outsourceProcess);
} }
/**
* 自动生成委外工序编号
*
*/
@Override
public String generateOutsourceProcessNo()
{
return redisCache.generateNo("OS");
}
/** /**
* 新增委外工序 * 新增委外工序
* *
* @param outsourceProcess 委外工序 * @param outsourceProcess 委外工序
* @return 结果 * @return 结果
*/ */
@Transactional(rollbackFor = Exception.class)
@Override @Override
public int insertOutsourceProcess(OutsourceProcess outsourceProcess) public int insertOutsourceProcess(OutsourceProcess outsourceProcess)
{ {
String loginName = ShiroUtils.getLoginName();
String outsourceProcessCode = redisCache.generateNo("WWGX");
outsourceProcess.setOutsourceProcessCode(outsourceProcessCode);
//更改日期格式,以提高可读性 outsourceProcess.setCreateBy(loginName);
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
String dataPart = df.format(new Date());
//移除日期中的分隔符以便于后续处理
String prefix = "WWGX"+dataPart.replace("-","");
//查询数据库中最大的编号
String maxCode = outsourceProcessMapper.findMaxRoundCode(prefix);
String newCode = generateNewCode(prefix,maxCode);
// outsourceProcess.setOutsourceProcessId();
outsourceProcess.setOutsourceProcessCode(newCode);
System.out.println(outsourceProcess.toString());
outsourceProcess.setCreateTime(DateUtils.getNowDate()); outsourceProcess.setCreateTime(DateUtils.getNowDate());
return outsourceProcessMapper.insertOutsourceProcess(outsourceProcess); return outsourceProcessMapper.insertOutsourceProcess(outsourceProcess);
} }
/**
*委外工序ID生产规则
*系统自动生成按照特定编码编码暂用ZCGX+年月日+001
*自增长:ZCGX20231111001ZCGX20231111002
*
*/
private String generateNewCode(String prefix, String maxCode) {
if (StringUtils.isEmpty(maxCode)){
return prefix+"001";
}
//解析并递增编号
int sequence = Integer.parseInt(maxCode.substring(4)) + 1 ;
// //检查序列号是否溢出
// if (sequence > 999){
// throw new BusinessException("当日编号已达到最大值999,请检查或调整策略");
// }
//格式化序列号,自动补零至三位
DecimalFormat df = new DecimalFormat("000");
return prefix + df.format(sequence);
}
/** /**
* 校验委外工序编号是否唯一 * 校验委外工序编号是否唯一
* *

54
ruoyi-admin/src/main/resources/templates/system/outsource_process/add.html

@ -10,7 +10,7 @@
<div class="form-group"> <div class="form-group">
<label class="col-sm-3 control-label is-required">委外工序编号:</label> <label class="col-sm-3 control-label is-required">委外工序编号:</label>
<div class="col-sm-8"> <div class="col-sm-8">
<input name="outsourceProcessNo" class="form-control" id="outsourceProcessNo" type="text" required> <input name="outsourceProcessNo" class="form-control" id="outsourceProcessNo" type="text" required readonly>
</div> </div>
</div> </div>
</div> </div>
@ -35,27 +35,39 @@
<th:block th:include="include :: footer" /> <th:block th:include="include :: footer" />
<script th:inline="javascript"> <script th:inline="javascript">
var prefix = ctx + "system/outsource_process" var prefix = ctx + "system/outsource_process"
$("#form-outsource_process-add").validate({ // $("#form-outsource_process-add").validate({
focusCleanup: true, // focusCleanup: true,
rules: { // rules: {
outsourceProcessNo: { // outsourceProcessNo: {
remote: { // remote: {
url: prefix + "/checkoutsourceProcessNoUnique", // url: prefix + "/checkoutsourceProcessNoUnique",
type: "post", // type: "post",
dataType: "json", // dataType: "json",
data: { // data: {
"outsourceProcessNo": function () { // "outsourceProcessNo": function () {
return $.common.trim($("#outsourceProcessNo").val()); // return $.common.trim($("#outsourceProcessNo").val());
} // }
} // }
} // }
}, // },
//
// },
// messages: {
// "outsourceProcessNo": {
// remote: "该工序编号已经存在"
// }
// }
// });
},
messages: { //获取单号
"outsourceProcessNo": { $.ajax({
remote: "该工序编号已经存在" url: prefix + "/generateOutsourceProcessNo",
} type: "GET",
dateType: "json",
success: function (resp) {
console.log(resp)
if (resp != null) {$("input[name='outsourceProcessNo']").val(resp);} else {$.modal.msgError("失败啦");}
} }
}); });

Loading…
Cancel
Save