Commit 78a4a48c by 胡懿

修改物资编码的生成规则

parent c7d6af4f
......@@ -18,9 +18,12 @@ import com.jeeplus.modules.warehouse.code.util.CodeUtil;
import com.jeeplus.modules.warehouse.code.util.StaticNumSeq;
import com.jeeplus.modules.warehouse.qrcode.entity.QrCode;
import com.jeeplus.modules.warehouse.qrcode.mapper.QrCodeMapper;
import com.jeeplus.modules.warehouse.qrcode.service.QrCodeService;
import com.jeeplus.modules.warehouse.qrcode.util.BuildQcUtil;
import com.jeeplus.modules.warehouse.qrcode.util.DrawQrcodeUtil;
import com.jeeplus.modules.warehouse.qrcode.util.TwoDimensionCode;
import com.jeeplus.modules.warehouse.wzcode.entity.Wzcode;
import com.jeeplus.modules.warehouse.wzcode.service.WzcodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
......@@ -46,6 +49,8 @@ public class GoodsService extends CrudService<GoodsMapper, Goods> {
private GoodsInfoMapper goodsInfoMapper;
@Autowired
private QrCodeMapper qrCodeMapper;
@Autowired
private WzcodeService wzcodeService;
public Goods get(String id) {
Goods goods = super.get(id);
......@@ -106,51 +111,50 @@ public class GoodsService extends CrudService<GoodsMapper, Goods> {
GoodsInfo temGi = new GoodsInfo();
temGi.setId(infoId);
temQr.setGoodsInfo(temGi);
List<QrCode> qrCodeList = qrCodeMapper.findByGoodsInfoId(temQr);
if (null != qrCodeList && qrCodeList.size() > 0) { // 二维码已经生成过
goodsInfo.setQrCodeList(qrCodeList);
return goodsInfo;
} else {
// 查询物资编码
Wzcode wzcode = wzcodeService.findByCode(goodsInfo.getType().getCode());
int wzNum = wzcode.getIntNum();
qrCodeList = new ArrayList<>();
int num = goodsInfo.getNum();
String beginNumSeq = "";
String endNumSeq = "";
String beginNumSeq = wzcode.getCode();
for (int i = 0; i < num; i++) {
String numSeq = CodeUtil.code("WZBM", StaticNumSeq.WZBM);
if (0 == i) {
beginNumSeq = numSeq;
}
if ((num - 1) == i) {
endNumSeq = numSeq;
}
wzNum ++;
wzcode.setIntNum(wzNum);
QrCode qrCode = new QrCode();
qrCode.setCode(numSeq);
qrCode.setCode(wzcode.getCodeAndNum());
qrCode.setGoodsInfo(goodsInfo);
qrCode.setState("0");
qrCode.preInsert();
try {
BuildQcUtil.buildQr(qrCode, qrImgPath + "/" + numSeq + ".png", qrImgPath + "/" + numSeq + "_" + i + ".png"); // 生成图片
BuildQcUtil.buildQr(qrCode, qrImgPath + "/" + wzcode.getCodeAndNum() + ".png", qrImgPath + "/" + wzcode.getCodeAndNum() + "_" + i + ".png"); // 生成图片
} catch (IOException e) {
e.printStackTrace();
}
qrCode.setUrl(Global.getAttachmentUrl() + "image/" + numSeq + "_" + i + ".png");
qrCode.setUrl(Global.getAttachmentUrl() + "image/" + wzcode.getCodeAndNum() + "_" + i + ".png");
qrCodeMapper.insert(qrCode);
qrCode = qrCodeMapper.get(qrCode.getId());
qrCodeList.add(qrCode);
}
String qrInterval = "";
if (beginNumSeq.equals(endNumSeq)) {
qrInterval = beginNumSeq;
} else {
qrInterval = beginNumSeq + "_" + endNumSeq.substring(13,17);
}
String qrInterval = beginNumSeq + "_" + wzcode.getNum();
goodsInfo.setQrInterval(qrInterval); // 设置编码区间
// goodsInfo.preUpdate();
goodsInfoMapper.update(goodsInfo);
goodsInfo.setQrCodeList(qrCodeList);
// 更新物资编码表
wzcodeService.save(wzcode);
return goodsInfo;
}
}
......
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.warehouse.wzcode.entity;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.core.persistence.DataEntity;
import com.jeeplus.common.utils.excel.annotation.ExcelField;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* 物资编码模块Entity
* @author 胡懿
* @version 2023-02-24
*/
public class Wzcode extends DataEntity<Wzcode> {
private static final long serialVersionUID = 1L;
private String code; // 类型编码
private String num; // 最后一个编码号
public Wzcode() {
super();
}
public Wzcode(String id){
super(id);
}
@ExcelField(title="类型编码", align=2, sort=1)
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
@ExcelField(title="最后一个编码号", align=2, sort=2)
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public void setIntNum(int n) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < (4 - (n + "").length()); i ++) {
sb.append("0");
}
this.num = sb.toString() + n;
}
public int getIntNum() {
if (StringUtils.isNotBlank(this.num)) {
return Integer.parseInt(this.num);
} else {
return 0;
}
}
public String getCodeAndNum() {
SimpleDateFormat sdf = new SimpleDateFormat("YYYY-MM");
return this.code + "-" + sdf.format(new Date()) + "-" + this.getNum();
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.warehouse.wzcode.mapper;
import com.jeeplus.core.persistence.BaseMapper;
import com.jeeplus.core.persistence.annotation.MyBatisMapper;
import com.jeeplus.modules.warehouse.wzcode.entity.Wzcode;
/**
* 物资编码模块MAPPER接口
* @author 胡懿
* @version 2023-02-24
*/
@MyBatisMapper
public interface WzcodeMapper extends BaseMapper<Wzcode> {
public Wzcode findByCode(Wzcode wzcode);
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.jeeplus.modules.warehouse.wzcode.mapper.WzcodeMapper">
<sql id="wzcodeColumns">
a.id AS "id",
a.code AS "code",
a.num AS "num",
a.create_by AS "createBy.id",
a.create_date AS "createDate",
a.update_by AS "updateBy.id",
a.update_date AS "updateDate",
a.remarks AS "remarks",
a.del_flag AS "delFlag"
</sql>
<sql id="wzcodeJoins">
</sql>
<select id="get" resultType="Wzcode" >
SELECT
<include refid="wzcodeColumns"/>
FROM t_wh_wzcode a
<include refid="wzcodeJoins"/>
WHERE a.id = #{id}
</select>
<select id="findList" resultType="Wzcode" >
SELECT
<include refid="wzcodeColumns"/>
FROM t_wh_wzcode a
<include refid="wzcodeJoins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
<if test="code != null and code != ''">
AND a.code = #{code}
</if>
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.update_date DESC
</otherwise>
</choose>
</select>
<select id="findAllList" resultType="Wzcode" >
SELECT
<include refid="wzcodeColumns"/>
FROM t_wh_wzcode a
<include refid="wzcodeJoins"/>
<where>
a.del_flag = #{DEL_FLAG_NORMAL}
${dataScope}
</where>
<choose>
<when test="page !=null and page.orderBy != null and page.orderBy != ''">
ORDER BY ${page.orderBy}
</when>
<otherwise>
ORDER BY a.update_date DESC
</otherwise>
</choose>
</select>
<insert id="insert">
INSERT INTO t_wh_wzcode(
id,
code,
num,
create_by,
create_date,
update_by,
update_date,
remarks,
del_flag
) VALUES (
#{id},
#{code},
#{num},
#{createBy.id},
#{createDate},
#{updateBy.id},
#{updateDate},
#{remarks},
#{delFlag}
)
</insert>
<update id="update">
UPDATE t_wh_wzcode SET
code = #{code},
num = #{num},
update_by = #{updateBy.id},
update_date = #{updateDate},
remarks = #{remarks}
WHERE id = #{id}
</update>
<!--物理删除-->
<update id="delete">
DELETE FROM t_wh_wzcode
WHERE id = #{id}
</update>
<!--逻辑删除-->
<update id="deleteByLogic">
UPDATE t_wh_wzcode SET
del_flag = #{DEL_FLAG_DELETE}
WHERE id = #{id}
</update>
<!-- 根据实体名称和字段名称和字段值获取唯一记录 -->
<select id="findUniqueByProperty" resultType="Wzcode" statementType="STATEMENT">
select * FROM t_wh_wzcode where ${propertyName} = '${value}'
</select>
<select id="findByCode" resultType="Wzcode" >
SELECT
<include refid="wzcodeColumns"/>
FROM t_wh_wzcode a
<include refid="wzcodeJoins"/>
<where>
<if test="code != null and code != ''">
AND a.code = #{code}
</if>
</where>
</select>
</mapper>
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.warehouse.wzcode.service;
import java.util.List;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.service.CrudService;
import com.jeeplus.modules.warehouse.wzcode.entity.Wzcode;
import com.jeeplus.modules.warehouse.wzcode.mapper.WzcodeMapper;
/**
* 物资编码模块Service
* @author 胡懿
* @version 2023-02-24
*/
@Service
@Transactional(readOnly = true)
public class WzcodeService extends CrudService<WzcodeMapper, Wzcode> {
public Wzcode get(String id) {
return super.get(id);
}
public List<Wzcode> findList(Wzcode wzcode) {
return super.findList(wzcode);
}
public Page<Wzcode> findPage(Page<Wzcode> page, Wzcode wzcode) {
return super.findPage(page, wzcode);
}
@Transactional(readOnly = false)
public void save(Wzcode wzcode) {
super.save(wzcode);
}
@Transactional(readOnly = false)
public void delete(Wzcode wzcode) {
super.delete(wzcode);
}
public Wzcode findByCode(String code) {
Wzcode tem = new Wzcode();
tem.setCode(code);
Wzcode wzcode = mapper.findByCode(tem);
if (null != wzcode) {
return wzcode;
} else {
tem.setIntNum(0);
return tem;
}
}
public static void main(String[] args) {
Wzcode tem = new Wzcode();
tem.setIntNum(123);
System.out.println(tem.getNum());
}
}
\ No newline at end of file
/**
* Copyright &copy; 2015-2020 <a href="http://www.jeeplus.org/">JeePlus</a> All rights reserved.
*/
package com.jeeplus.modules.warehouse.wzcode.web;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolationException;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.multipart.MultipartFile;
import com.google.common.collect.Lists;
import com.jeeplus.common.utils.DateUtils;
import com.jeeplus.common.config.Global;
import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.core.web.BaseController;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.common.utils.excel.ExportExcel;
import com.jeeplus.common.utils.excel.ImportExcel;
import com.jeeplus.modules.warehouse.wzcode.entity.Wzcode;
import com.jeeplus.modules.warehouse.wzcode.service.WzcodeService;
/**
* 物资编码模块Controller
* @author 胡懿
* @version 2023-02-24
*/
@Controller
@RequestMapping(value = "${adminPath}/warehouse/wzcode/wzcode")
public class WzcodeController extends BaseController {
@Autowired
private WzcodeService wzcodeService;
@ModelAttribute
public Wzcode get(@RequestParam(required=false) String id) {
Wzcode entity = null;
if (StringUtils.isNotBlank(id)){
entity = wzcodeService.get(id);
}
if (entity == null){
entity = new Wzcode();
}
return entity;
}
/**
* 物资编码模块列表页面
*/
@RequiresPermissions("warehouse:wzcode:wzcode:list")
@RequestMapping(value = {"list", ""})
public String list(Wzcode wzcode, Model model) {
model.addAttribute("wzcode", wzcode);
return "modules/warehouse/wzcode/wzcodeList";
}
/**
* 物资编码模块列表数据
*/
@ResponseBody
@RequiresPermissions("warehouse:wzcode:wzcode:list")
@RequestMapping(value = "data")
public Map<String, Object> data(Wzcode wzcode, HttpServletRequest request, HttpServletResponse response, Model model) {
Page<Wzcode> page = wzcodeService.findPage(new Page<Wzcode>(request, response), wzcode);
return getBootstrapData(page);
}
/**
* 查看,增加,编辑物资编码模块表单页面
*/
@RequiresPermissions(value={"warehouse:wzcode:wzcode:view","warehouse:wzcode:wzcode:add","warehouse:wzcode:wzcode:edit"},logical=Logical.OR)
@RequestMapping(value = "form/{mode}")
public String form(@PathVariable String mode, Wzcode wzcode, Model model) {
model.addAttribute("wzcode", wzcode);
model.addAttribute("mode", mode);
return "modules/warehouse/wzcode/wzcodeForm";
}
/**
* 保存物资编码模块
*/
@ResponseBody
@RequiresPermissions(value={"warehouse:wzcode:wzcode:add","warehouse:wzcode:wzcode:edit"},logical=Logical.OR)
@RequestMapping(value = "save")
public AjaxJson save(Wzcode wzcode, Model model) throws Exception{
AjaxJson j = new AjaxJson();
/**
* 后台hibernate-validation插件校验
*/
String errMsg = beanValidator(wzcode);
if (StringUtils.isNotBlank(errMsg)){
j.setSuccess(false);
j.setMsg(errMsg);
return j;
}
//新增或编辑表单保存
wzcodeService.save(wzcode);//保存
j.setSuccess(true);
j.setMsg("保存物资编码模块成功");
return j;
}
/**
* 删除物资编码模块
*/
@ResponseBody
@RequiresPermissions("warehouse:wzcode:wzcode:del")
@RequestMapping(value = "delete")
public AjaxJson delete(Wzcode wzcode) {
AjaxJson j = new AjaxJson();
wzcodeService.delete(wzcode);
j.setMsg("删除物资编码模块成功");
return j;
}
/**
* 批量删除物资编码模块
*/
@ResponseBody
@RequiresPermissions("warehouse:wzcode:wzcode:del")
@RequestMapping(value = "deleteAll")
public AjaxJson deleteAll(String ids) {
AjaxJson j = new AjaxJson();
String idArray[] =ids.split(",");
for(String id : idArray){
wzcodeService.delete(wzcodeService.get(id));
}
j.setMsg("删除物资编码模块成功");
return j;
}
/**
* 导出excel文件
*/
@ResponseBody
@RequiresPermissions("warehouse:wzcode:wzcode:export")
@RequestMapping(value = "export")
public AjaxJson exportFile(Wzcode wzcode, HttpServletRequest request, HttpServletResponse response) {
AjaxJson j = new AjaxJson();
try {
String fileName = "物资编码模块"+DateUtils.getDate("yyyyMMddHHmmss")+".xlsx";
Page<Wzcode> page = wzcodeService.findPage(new Page<Wzcode>(request, response, -1), wzcode);
new ExportExcel("物资编码模块", Wzcode.class).setDataList(page.getList()).write(response, fileName).dispose();
j.setSuccess(true);
j.setMsg("导出成功!");
return j;
} catch (Exception e) {
j.setSuccess(false);
j.setMsg("导出物资编码模块记录失败!失败信息:"+e.getMessage());
}
return j;
}
/**
* 导入Excel数据
*/
@ResponseBody
@RequiresPermissions("warehouse:wzcode:wzcode:import")
@RequestMapping(value = "import")
public AjaxJson importFile(@RequestParam("file")MultipartFile file, HttpServletResponse response, HttpServletRequest request) {
AjaxJson j = new AjaxJson();
try {
int successNum = 0;
int failureNum = 0;
StringBuilder failureMsg = new StringBuilder();
ImportExcel ei = new ImportExcel(file, 1, 0);
List<Wzcode> list = ei.getDataList(Wzcode.class);
for (Wzcode wzcode : list){
try{
wzcodeService.save(wzcode);
successNum++;
}catch(ConstraintViolationException ex){
failureNum++;
}catch (Exception ex) {
failureNum++;
}
}
if (failureNum>0){
failureMsg.insert(0, ",失败 "+failureNum+" 条物资编码模块记录。");
}
j.setMsg( "已成功导入 "+successNum+" 条物资编码模块记录"+failureMsg);
} catch (Exception e) {
j.setSuccess(false);
j.setMsg("导入物资编码模块失败!失败信息:"+e.getMessage());
}
return j;
}
/**
* 下载导入物资编码模块数据模板
*/
@ResponseBody
@RequiresPermissions("warehouse:wzcode:wzcode:import")
@RequestMapping(value = "import/template")
public AjaxJson importFileTemplate(HttpServletResponse response) {
AjaxJson j = new AjaxJson();
try {
String fileName = "物资编码模块数据导入模板.xlsx";
List<Wzcode> list = Lists.newArrayList();
new ExportExcel("物资编码模块数据", Wzcode.class, 1).setDataList(list).write(response, fileName).dispose();
return null;
} catch (Exception e) {
j.setSuccess(false);
j.setMsg( "导入模板下载失败!失败信息:"+e.getMessage());
}
return j;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment