Pārlūkot izejas kodu

修改了“计量物料配置表直接录入”接口

duyong 4 gadi atpakaļ
vecāks
revīzija
f3402b8c6b

+ 25 - 6
src/main/java/com/steerinfo/baseinfo/meterbasematterinfodirect/controller/MeterBaseMatterInfoDirectController.java

@@ -13,6 +13,8 @@ import io.swagger.annotations.ApiOperation;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.Arrays;
@@ -70,9 +72,18 @@ public class MeterBaseMatterInfoDirectController extends BaseRESTfulController {
     @ApiImplicitParam(name = "meterBaseMatterInfoDirect", value = "详细实体meterBaseMatterInfoDirect", required = true, dataType = "MeterBaseMatterInfoDirect")
     //@RequiresPermissions("meterbasematterinfodirect:create")
     @PostMapping(value = "/")
-    public RESTfulResult add(@ModelAttribute MeterBaseMatterInfoDirect model){
-        MeterBaseMatterInfoDirect meterBaseMatterInfoDirect = meterBaseMatterInfoDirectService.add(model);
-        return success(meterBaseMatterInfoDirect);
+    public RESTfulResult add(@RequestBody MeterBaseMatterInfoDirect model){
+        try{
+            String msg = meterBaseMatterInfoDirectService.checkandadd(model);
+            if(msg != null && !msg.equals("")){
+                return failed(null,msg);
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+            return failed(null, "操作异常,请确认!");
+        }
+
+        return success();
     }
 
     @ApiOperation(value="获取详细信息", notes="根据url的id来获取详细信息")
@@ -92,9 +103,17 @@ public class MeterBaseMatterInfoDirectController extends BaseRESTfulController {
     //@RequiresPermissions("meterbasematterinfodirect:update")
     @PutMapping(value = "/{id}", produces  = "application/json;charset=UTF-8")
     public RESTfulResult update(@PathVariable String id, @RequestBody MeterBaseMatterInfoDirect model){
-        model.setId(id);
-        MeterBaseMatterInfoDirect meterBaseMatterInfoDirect = meterBaseMatterInfoDirectService.modify(model);
-        return success(meterBaseMatterInfoDirect);
+        try{
+            String msg = meterBaseMatterInfoDirectService.checkandupdate(id,model);
+            if (msg != null && !msg.equals("")) {
+                return failed(null,msg);
+            }
+        }
+        catch (Exception e){
+            e.printStackTrace();
+            return failed(null,"操作异常,请确认!");
+        }
+        return success();
     }
 
     @ApiOperation(value="删除", notes="根据url的id来指定删除对象")

+ 7 - 0
src/main/java/com/steerinfo/baseinfo/meterbasematterinfodirect/mapper/MeterBaseMatterInfoDirectMapper.java

@@ -1,10 +1,17 @@
 package com.steerinfo.baseinfo.meterbasematterinfodirect.mapper;
 
+import com.steerinfo.baseinfo.meterbasematterinfo.model.MeterBaseMatterInfo;
 import com.steerinfo.baseinfo.meterbasematterinfodirect.model.MeterBaseMatterInfoDirect;
 import com.steerinfo.framework.mapper.IBaseMapper;
 import java.math.*;
+import java.util.List;
+import java.util.Map;
+
 import org.apache.ibatis.annotations.Mapper;
 
 @Mapper
 public interface MeterBaseMatterInfoDirectMapper extends IBaseMapper<MeterBaseMatterInfoDirect, String> {
+    String GetNewID();
+
+    List<MeterBaseMatterInfo> selectForUpdate(Map<String, Object> parameters);
 }

+ 20 - 1
src/main/java/com/steerinfo/baseinfo/meterbasematterinfodirect/mapper/MeterBaseMatterInfoDirectMapper.xml

@@ -880,5 +880,24 @@
   </delete>
   <!-- 友情提示!!!-->
   <!-- 请将自己写的代码放在此标签之下,方便以后粘贴复制。-->
-  
+
+  <select id="GetNewID" parameterType="java.lang.String" resultType="java.lang.String">
+    SELECT LPAD(NVL(MAX(TO_NUMBER(SUBSTR(MATTER_NO, LENGTH(MATTER_NO) - 4))),0) + 1,5,'0') MATTER_NO
+    FROM METER_BASE_MATTER_INFO_DIRECT
+  </select>
+
+  <select id="selectForUpdate" parameterType="java.util.HashMap" resultMap="BaseResultMap">
+    <include refid="select"/>
+    <where>
+      <if test="matterNo != null and matterNo != ''">
+        and MATTER_NO != #{matterNo}
+      </if>
+      <if test="matterName != null and matterName != ''">
+        and MATTER_NAME = #{matterName}
+      </if>
+      <if test="meterCode != null and meterCode != ''">
+        and METER_CODE = #{meterCode}
+      </if>
+    </where>
+  </select>
 </mapper>

+ 4 - 0
src/main/java/com/steerinfo/baseinfo/meterbasematterinfodirect/service/IMeterBaseMatterInfoDirectService.java

@@ -1,5 +1,7 @@
 package com.steerinfo.baseinfo.meterbasematterinfodirect.service;
 
+import com.steerinfo.baseinfo.meterbasedriver.model.MeterBaseDriver;
+import com.steerinfo.baseinfo.meterbasematterinfo.model.MeterBaseMatterInfo;
 import com.steerinfo.framework.service.IBaseService;
 import com.steerinfo.baseinfo.meterbasematterinfodirect.model.MeterBaseMatterInfoDirect;
 import java.util.Date;
@@ -19,5 +21,7 @@ import java.math.BigDecimal;
  * @Copyright 湖南视拓信息技术股份有限公司. All rights reserved.
  */
 public interface IMeterBaseMatterInfoDirectService extends IBaseService<MeterBaseMatterInfoDirect, String>{
+    String checkandadd(MeterBaseMatterInfoDirect model);
 
+    String checkandupdate(String id, MeterBaseMatterInfoDirect model);
 }

+ 72 - 0
src/main/java/com/steerinfo/baseinfo/meterbasematterinfodirect/service/impl/MeterBaseMatterInfoDirectServiceImpl.java

@@ -1,14 +1,20 @@
 package com.steerinfo.baseinfo.meterbasematterinfodirect.service.impl;
 
+import com.steerinfo.baseinfo.meterbasedriver.model.MeterBaseDriver;
+import com.steerinfo.baseinfo.meterbasematterinfo.model.MeterBaseMatterInfo;
 import com.steerinfo.framework.mapper.IBaseMapper;
 import com.steerinfo.framework.service.impl.BaseServiceImpl;
 import com.steerinfo.baseinfo.meterbasematterinfodirect.model.MeterBaseMatterInfoDirect;
 import com.steerinfo.baseinfo.meterbasematterinfodirect.mapper.MeterBaseMatterInfoDirectMapper;
 import com.steerinfo.baseinfo.meterbasematterinfodirect.service.IMeterBaseMatterInfoDirectService;
+import com.steerinfo.framework.user.UserPayload;
+import com.steerinfo.util.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import java.util.Date;
 import java.math.BigDecimal;
+import java.util.HashMap;
+import java.util.List;
 
 /**
  * MeterBaseMatterInfoDirect服务实现:
@@ -33,4 +39,70 @@ public class MeterBaseMatterInfoDirectServiceImpl extends BaseServiceImpl<MeterB
     protected IBaseMapper<MeterBaseMatterInfoDirect, String> getMapper() {
         return meterBaseMatterInfoDirectMapper;
     }
+
+    @Override
+    public String checkandadd(MeterBaseMatterInfoDirect model) {
+        if (StringUtils.isEmpty(model.getMatterName())) {
+            return "物料名称不能为空";
+        }
+        if (StringUtils.isNotEmpty(model.getMeterCode()) && model.getMeterCode().contains("000")) {
+            return "物料的计量码不允许包含【000】,此编号已被临时委托使用!";
+        }
+        if (StringUtils.isNotEmpty(model.getMeterCode())) {
+            HashMap<String, Object> obj2 = new HashMap<>();
+            obj2.put("meterCode", model.getMeterCode());
+            List<MeterBaseMatterInfoDirect> com2 = meterBaseMatterInfoDirectMapper.selectByParameters(obj2);
+            if (com2 != null && com2.size() > 0) {
+                return "该计量码已存在!";
+            }
+        }
+        HashMap<String, Object> obj1 = new HashMap<>();
+        obj1.put("matterName", model.getMatterName());
+        List<MeterBaseMatterInfoDirect> com1 = meterBaseMatterInfoDirectMapper.selectByParameters(obj1);
+        if (!com1.isEmpty()) {
+            return "该物料名称已存在";
+        }
+        String no = meterBaseMatterInfoDirectMapper.GetNewID();
+        model.setMatterNo(no);
+        model.setCreateTime(new Date());
+        model.setValidFlag("1");//有效
+        meterBaseMatterInfoDirectMapper.insert(model);
+        return "";
+    }
+
+    @Override
+    public String checkandupdate(String id, MeterBaseMatterInfoDirect model) {
+        if (model.getMatterName() == null || model.getMatterName().equals("")) {
+            return "物料名称不能为空";
+        }
+        if (StringUtils.isNotEmpty(model.getMeterCode()) && model.getMeterCode().contains("000")) {
+            return "物料的计量码不允许包含【000】,此编号已被临时委托使用!";
+        }
+        if (StringUtils.isNotEmpty(model.getMeterCode())) {
+            HashMap<String, Object> obj = new HashMap<>();
+            obj.put("meterCode", model.getMeterCode());
+            obj.put("matterNo", id);
+            List<MeterBaseMatterInfo> com = meterBaseMatterInfoDirectMapper.selectForUpdate(obj);
+            if (!com.isEmpty() && com.size() > 1) {
+                return "该计量码已存在!";
+            }
+            if (!com.isEmpty() && com.size() == 1 && !com.get(0).getMatterNo().equals(id)) {
+                return "该计量码已存在!";
+            }
+        }
+
+        HashMap<String, Object> obj1 = new HashMap<>();
+        obj1.put("matterName", model.getMatterName());
+        obj1.put("matterNo", id);
+        List<MeterBaseMatterInfo> com = meterBaseMatterInfoDirectMapper.selectForUpdate(obj1);
+        if (!com.isEmpty() && com.size() > 1) {
+            return "该物料名称已存在!";
+        }
+        if (!com.isEmpty() && com.size() == 1 && !com.get(0).getMatterNo().equals(id)) {
+            return "该物料名称已存在!";
+        }
+        model.setUpdateTime(new Date());
+        meterBaseMatterInfoDirectMapper.updateByPrimaryKey(model);
+        return "";
+    }
 }