Browse Source

物料页面后台

FEI 3 weeks ago
parent
commit
51000fa08b

+ 73
- 0
sto/src/main/java/com/shinsoft/sto/controller/main/MaterialController.java View File

@@ -0,0 +1,73 @@
1
+package com.shinsoft.sto.controller.main;
2
+
3
+import com.alibaba.fastjson.JSON;
4
+import com.shinsoft.sto.model.main.Material;
5
+import com.shinsoft.sto.service.main.MaterialService;
6
+import com.shinsoft.sto.model.system.ResultJSON;
7
+import org.springframework.beans.factory.annotation.Autowired;
8
+import org.springframework.web.bind.annotation.*;
9
+
10
+import javax.servlet.http.HttpServletRequest;
11
+
12
+@RestController
13
+@RequestMapping("/Material")
14
+public class MaterialController {
15
+
16
+    @Autowired
17
+    private MaterialService materialService;
18
+
19
+    @GetMapping("/query")
20
+    public ResultJSON query(@RequestParam(defaultValue = "1") int page,
21
+                           @RequestParam(defaultValue = "50") int rows,
22
+                           @RequestParam(required = false) String material,
23
+                           @RequestParam(required = false) String standard,
24
+                           HttpServletRequest request) {
25
+        try {
26
+            String userId = (String) request.getHeader("userId");
27
+            String belongId = (String) request.getHeader("belongId");
28
+            
29
+            return materialService.query(page, rows, material, standard, userId, belongId);
30
+        } catch (Exception ex) {
31
+            ex.printStackTrace();
32
+            return ResultJSON.error("查询失败:" + ex.getMessage());
33
+        }
34
+    }
35
+
36
+    @PostMapping("/save")
37
+    public ResultJSON save(@RequestParam String json,
38
+                          HttpServletRequest request) {
39
+        try {
40
+            String userId = (String) request.getHeader("userId");
41
+            String belongId = (String) request.getHeader("belongId");
42
+            
43
+            Material material = JSON.parseObject(json, Material.class);
44
+            return materialService.save(material, userId, belongId);
45
+        } catch (Exception ex) {
46
+            ex.printStackTrace();
47
+            return ResultJSON.error("保存失败:" + ex.getMessage());
48
+        }
49
+    }
50
+
51
+    @PostMapping("/remove")
52
+    public ResultJSON remove(@RequestParam String id,
53
+                            HttpServletRequest request) {
54
+        try {
55
+            String userId = (String) request.getHeader("userId");
56
+            return materialService.remove(id, userId);
57
+        } catch (Exception ex) {
58
+            ex.printStackTrace();
59
+            return ResultJSON.error("删除失败:" + ex.getMessage());
60
+        }
61
+    }
62
+
63
+    @GetMapping("/options")
64
+    public ResultJSON getOptions(HttpServletRequest request) {
65
+        try {
66
+            String belongId = (String) request.getHeader("belongId");
67
+            return ResultJSON.success(materialService.getMaterialOptions(belongId));
68
+        } catch (Exception ex) {
69
+            ex.printStackTrace();
70
+            return ResultJSON.error("获取选项失败:" + ex.getMessage());
71
+        }
72
+    }
73
+}

+ 29
- 0
sto/src/main/java/com/shinsoft/sto/mapper/main/MaterialMapper.java View File

@@ -0,0 +1,29 @@
1
+package com.shinsoft.sto.mapper.main;
2
+
3
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
4
+import com.baomidou.mybatisplus.core.metadata.IPage;
5
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
6
+import com.shinsoft.sto.model.main.Material;
7
+import org.apache.ibatis.annotations.Param;
8
+import org.apache.ibatis.annotations.Select;
9
+
10
+import java.util.List;
11
+
12
+public interface MaterialMapper extends BaseMapper<Material> {
13
+
14
+    /**
15
+     * 查询物料下拉框数据
16
+     */
17
+    @Select("SELECT id as value, material_name as label FROM T_MAIN_MATERIAL WHERE nvl(cancel_flag,'0') = '0' and belong_id = #{belongId}")
18
+    List<com.shinsoft.sto.model.common.selectModel> selectMaterialOptions(String belongId);
19
+
20
+    /**
21
+     * 分页查询物料列表
22
+     */
23
+    IPage<Material> selectMaterialPage(Page<Material> page, @Param("material") String material, @Param("standard") String standard, @Param("belongId") String belongId);
24
+
25
+    /**
26
+     * 根据物料名称查询
27
+     */
28
+    List<Material> selectByMaterialName(@Param("materialName") String materialName, @Param("belongId") String belongId);
29
+}

+ 69
- 0
sto/src/main/java/com/shinsoft/sto/mapper/main/MaterialMapper.xml View File

@@ -0,0 +1,69 @@
1
+<?xml version="1.0" encoding="UTF-8" ?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
3
+<mapper namespace="com.shinsoft.sto.mapper.main.MaterialMapper">
4
+
5
+    <resultMap id="BaseResultMap" type="com.shinsoft.sto.model.main.Material">
6
+        <id column="id" property="id" jdbcType="VARCHAR"/>
7
+        <result column="process_instance_id" property="processInstanceId" jdbcType="VARCHAR"/>
8
+        <result column="process_instance_status" property="processInstanceStatus" jdbcType="VARCHAR"/>
9
+        <result column="add_id" property="addId" jdbcType="VARCHAR"/>
10
+        <result column="add_code" property="addCode" jdbcType="VARCHAR"/>
11
+        <result column="add_name" property="addName" jdbcType="VARCHAR"/>
12
+        <result column="add_dept_id" property="addDeptId" jdbcType="VARCHAR"/>
13
+        <result column="add_dept_code" property="addDeptCode" jdbcType="VARCHAR"/>
14
+        <result column="add_dept_name" property="addDeptName" jdbcType="VARCHAR"/>
15
+        <result column="add_time" property="addTime" jdbcType="TIMESTAMP"/>
16
+        <result column="modify_id" property="modifyId" jdbcType="VARCHAR"/>
17
+        <result column="modify_code" property="modifyCode" jdbcType="VARCHAR"/>
18
+        <result column="modify_name" property="modifyName" jdbcType="VARCHAR"/>
19
+        <result column="modify_time" property="modifyTime" jdbcType="TIMESTAMP"/>
20
+        <result column="cancel_id" property="cancelId" jdbcType="VARCHAR"/>
21
+        <result column="cancel_code" property="cancelCode" jdbcType="VARCHAR"/>
22
+        <result column="cancel_name" property="cancelName" jdbcType="VARCHAR"/>
23
+        <result column="cancel_time" property="cancelTime" jdbcType="TIMESTAMP"/>
24
+        <result column="cancel_flag" property="cancelFlag" jdbcType="VARCHAR"/>
25
+        <result column="belong_id" property="belongId" jdbcType="VARCHAR"/>
26
+        <result column="material_name" property="materialName" jdbcType="VARCHAR"/>
27
+        <result column="material_code" property="materialCode" jdbcType="VARCHAR"/>
28
+        <result column="material_standard" property="materialStandard" jdbcType="VARCHAR"/>
29
+        <result column="material_model" property="materialModel" jdbcType="VARCHAR"/>
30
+        <result column="material_attr1" property="materialAttr1" jdbcType="VARCHAR"/>
31
+        <result column="material_attr2" property="materialAttr2" jdbcType="VARCHAR"/>
32
+        <result column="material_attr3" property="materialAttr3" jdbcType="VARCHAR"/>
33
+        <result column="material_attr4" property="materialAttr4" jdbcType="VARCHAR"/>
34
+        <result column="material_attr5" property="materialAttr5" jdbcType="VARCHAR"/>
35
+    </resultMap>
36
+
37
+    <sql id="Base_Column_List">
38
+        id, process_instance_id, process_instance_status, add_id, add_code, add_name, add_dept_id,
39
+        add_dept_code, add_dept_name, add_time, modify_id, modify_code, modify_name, modify_time, cancel_id,
40
+        cancel_code, cancel_name, cancel_time, cancel_flag, belong_id, material_name, material_code,
41
+        material_standard, material_model, material_attr1, material_attr2, material_attr3, material_attr4, material_attr5
42
+    </sql>
43
+
44
+    <select id="selectMaterialPage" resultMap="BaseResultMap">
45
+        select
46
+        <include refid="Base_Column_List"/>
47
+        from T_MAIN_MATERIAL
48
+        where nvl(cancel_flag,'0') = '0'
49
+        and belong_id = #{belongId}
50
+        <if test="material != null and material != ''">
51
+            and (material_name like '%' || #{material} || '%'
52
+            or material_code like '%' || #{material} || '%')
53
+        </if>
54
+        <if test="standard != null and standard != ''">
55
+            and material_standard like '%' || #{standard} || '%'
56
+        </if>
57
+        order by add_time desc
58
+    </select>
59
+
60
+    <select id="selectByMaterialName" resultMap="BaseResultMap">
61
+        select
62
+        <include refid="Base_Column_List"/>
63
+        from T_MAIN_MATERIAL
64
+        where nvl(cancel_flag,'0') = '0'
65
+        and belong_id = #{belongId}
66
+        and material_name = #{materialName}
67
+    </select>
68
+
69
+</mapper>

+ 107
- 0
sto/src/main/java/com/shinsoft/sto/model/main/Material.java View File

@@ -0,0 +1,107 @@
1
+package com.shinsoft.sto.model.main;
2
+
3
+import com.baomidou.mybatisplus.annotation.*;
4
+import com.shinsoft.generator.model.BaseModel;
5
+import io.swagger.annotations.ApiModel;
6
+import io.swagger.annotations.ApiModelProperty;
7
+import lombok.Getter;
8
+import lombok.Setter;
9
+import lombok.experimental.Accessors;
10
+
11
+import java.util.Date;
12
+
13
+@Getter
14
+@Setter
15
+@Accessors(chain = true)
16
+@TableName("T_MAIN_MATERIAL")
17
+@ApiModel(value = "物料", description = "物料基本信息表")
18
+public class Material extends BaseModel {
19
+
20
+    @TableId(type = IdType.ASSIGN_UUID)
21
+    @ApiModelProperty("主键ID")
22
+    private String id;
23
+
24
+    @ApiModelProperty("流程实例ID")
25
+    private String processInstanceId;
26
+
27
+    @ApiModelProperty("流程实例状态")
28
+    private String processInstanceStatus;
29
+
30
+    @ApiModelProperty("添加人ID")
31
+    private String addId;
32
+
33
+    @ApiModelProperty("添加人编码")
34
+    private String addCode;
35
+
36
+    @ApiModelProperty("添加人名称")
37
+    private String addName;
38
+
39
+    @ApiModelProperty("添加部门ID")
40
+    private String addDeptId;
41
+
42
+    @ApiModelProperty("添加部门编码")
43
+    private String addDeptCode;
44
+
45
+    @ApiModelProperty("添加部门名称")
46
+    private String addDeptName;
47
+
48
+    @ApiModelProperty("添加时间")
49
+    private Date addTime;
50
+
51
+    @ApiModelProperty("修改人ID")
52
+    private String modifyId;
53
+
54
+    @ApiModelProperty("修改人编码")
55
+    private String modifyCode;
56
+
57
+    @ApiModelProperty("修改人名称")
58
+    private String modifyName;
59
+
60
+    @ApiModelProperty("修改时间")
61
+    private Date modifyTime;
62
+
63
+    @ApiModelProperty("作废人ID")
64
+    private String cancelId;
65
+
66
+    @ApiModelProperty("作废人编码")
67
+    private String cancelCode;
68
+
69
+    @ApiModelProperty("作废人名称")
70
+    private String cancelName;
71
+
72
+    @ApiModelProperty("作废时间")
73
+    private Date cancelTime;
74
+
75
+    @ApiModelProperty("作废标记")
76
+    private String cancelFlag;
77
+
78
+    @ApiModelProperty("所属组织ID")
79
+    private String belongId;
80
+
81
+    @ApiModelProperty("物料名称")
82
+    private String materialName;
83
+
84
+    @ApiModelProperty("物料编码")
85
+    private String materialCode;
86
+
87
+    @ApiModelProperty("物料类别")
88
+    private String materialStandard;
89
+
90
+    @ApiModelProperty("物料尺寸")
91
+    private String materialModel;
92
+
93
+    @ApiModelProperty("物料属性1")
94
+    private String materialAttr1;
95
+
96
+    @ApiModelProperty("物料属性2")
97
+    private String materialAttr2;
98
+
99
+    @ApiModelProperty("物料属性3")
100
+    private String materialAttr3;
101
+
102
+    @ApiModelProperty("物料属性4")
103
+    private String materialAttr4;
104
+
105
+    @ApiModelProperty("物料属性5")
106
+    private String materialAttr5;
107
+}

+ 103
- 0
sto/src/main/java/com/shinsoft/sto/service/impl/main/MaterialServiceImp.java View File

@@ -0,0 +1,103 @@
1
+package com.shinsoft.sto.service.impl.main;
2
+
3
+import com.baomidou.mybatisplus.core.metadata.IPage;
4
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
5
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
6
+import com.shinsoft.sto.mapper.main.MaterialMapper;
7
+import com.shinsoft.sto.model.main.Material;
8
+import com.shinsoft.sto.service.main.MaterialService;
9
+import com.shinsoft.sto.model.system.ResponseCodeMsg;
10
+import com.shinsoft.sto.model.system.ResultJSON;
11
+import org.springframework.stereotype.Service;
12
+
13
+import java.util.Date;
14
+import java.util.List;
15
+
16
+@Service
17
+public class MaterialServiceImp extends ServiceImpl<MaterialMapper, Material> implements MaterialService {
18
+
19
+    @Override
20
+    public ResultJSON query(int page, int rows, String material, String standard, String userId, String belongId) {
21
+        try {
22
+            Page<Material> pageParam = new Page<>(page, rows);
23
+            IPage<Material> materialPage = baseMapper.selectMaterialPage(pageParam, material, standard, belongId);
24
+
25
+            return ResultJSON.success(materialPage);
26
+        } catch (Exception ex) {
27
+            ex.printStackTrace();
28
+            return ResultJSON.error(ResponseCodeMsg.CODE_EX, ex.getMessage());
29
+        }
30
+    }
31
+
32
+    @Override
33
+    public ResultJSON save(Material material, String userId, String belongId) {
34
+        try {
35
+            // 检查物料名称是否重复
36
+            if (material.getId() == null || material.getId().isEmpty()) {
37
+                // 新增
38
+                List<Material> existingMaterials = baseMapper.selectByMaterialName(material.getMaterialName(), belongId);
39
+                if (existingMaterials != null && !existingMaterials.isEmpty()) {
40
+                    return ResultJSON.error("物料名称已存在,请勿重复添加");
41
+                }
42
+
43
+                // 设置新增信息
44
+                material.setAddId(userId);
45
+                material.setAddTime(new Date());
46
+                material.setCancelFlag("0");
47
+                material.setBelongId(belongId);
48
+
49
+                boolean success = save(material);
50
+                return success ? ResultJSON.success("新增成功") : ResultJSON.error("新增失败");
51
+            } else {
52
+                // 更新
53
+                Material existingMaterial = getById(material.getId());
54
+                if (existingMaterial == null) {
55
+                    return ResultJSON.error("物料不存在");
56
+                }
57
+
58
+                // 检查除当前记录外是否有相同物料名称
59
+                List<Material> sameNameMaterials = baseMapper.selectByMaterialName(material.getMaterialName(), belongId);
60
+                if (sameNameMaterials != null && sameNameMaterials.stream()
61
+                        .anyMatch(m -> !m.getId().equals(material.getId()))) {
62
+                    return ResultJSON.error("物料名称已存在,请修改");
63
+                }
64
+
65
+                // 设置更新信息
66
+                material.setModifyId(userId);
67
+                material.setModifyTime(new Date());
68
+
69
+                boolean success = updateById(material);
70
+                return success ? ResultJSON.success("更新成功") : ResultJSON.error("更新失败");
71
+            }
72
+        } catch (Exception ex) {
73
+            ex.printStackTrace();
74
+            return ResultJSON.error(ResponseCodeMsg.CODE_EX, ex.getMessage());
75
+        }
76
+    }
77
+
78
+    @Override
79
+    public ResultJSON remove(String id, String userId) {
80
+        try {
81
+            Material material = getById(id);
82
+            if (material == null) {
83
+                return ResultJSON.error("物料不存在");
84
+            }
85
+
86
+            // 软删除
87
+            material.setCancelFlag("9");
88
+            material.setCancelId(userId);
89
+            material.setCancelTime(new Date());
90
+
91
+            boolean success = updateById(material);
92
+            return success ? ResultJSON.success("删除成功") : ResultJSON.error("删除失败");
93
+        } catch (Exception ex) {
94
+            ex.printStackTrace();
95
+            return ResultJSON.error(ResponseCodeMsg.CODE_EX, ex.getMessage());
96
+        }
97
+    }
98
+
99
+    @Override
100
+    public List<com.shinsoft.sto.model.common.selectModel> getMaterialOptions(String belongId) {
101
+        return baseMapper.selectMaterialOptions(belongId);
102
+    }
103
+}

+ 29
- 0
sto/src/main/java/com/shinsoft/sto/service/main/MaterialService.java View File

@@ -0,0 +1,29 @@
1
+package com.shinsoft.sto.service.main;
2
+
3
+import com.shinsoft.sto.model.main.Material;
4
+import com.shinsoft.sto.model.system.ResultJSON;
5
+
6
+import java.util.List;
7
+
8
+public interface MaterialService {
9
+
10
+    /**
11
+     * 分页查询物料列表
12
+     */
13
+    ResultJSON query(int page, int rows, String material, String standard, String userId, String belongId);
14
+
15
+    /**
16
+     * 保存物料信息
17
+     */
18
+    ResultJSON save(Material material, String userId, String belongId);
19
+
20
+    /**
21
+     * 删除物料(软删除)
22
+     */
23
+    ResultJSON remove(String id, String userId);
24
+
25
+    /**
26
+     * 获取物料下拉选项
27
+     */
28
+    List<com.shinsoft.sto.model.common.selectModel> getMaterialOptions(String belongId);
29
+}

Loading…
Cancel
Save