anderx 1 год назад
Родитель
Сommit
87ee18d801

+ 1 - 0
src/main/java/com/goafanti/business/controller/RestrictProjectController.java

@@ -22,6 +22,7 @@ public class RestrictProjectController extends CertifyApiController {
     @RequestMapping(value = "/add", method = RequestMethod.POST)
     public Result add(InputRestrictProject in){
         Result res = res();
+
         return res.data(restrictProjectService.add(in));
     }
 }

+ 1 - 0
src/main/java/com/goafanti/business/service/RestrictProjectService.java

@@ -4,4 +4,5 @@ import com.goafanti.business.bo.InputRestrictProject;
 
 public interface RestrictProjectService {
     int add(InputRestrictProject in);
+
 }

+ 18 - 2
src/main/java/com/goafanti/business/service/impl/RestrictProjectServiceImpl.java

@@ -3,11 +3,16 @@ package com.goafanti.business.service.impl;
 import com.goafanti.business.bo.InputRestrictProject;
 import com.goafanti.business.service.RestrictProjectService;
 import com.goafanti.common.dao.RestrictProjectMapper;
+import com.goafanti.common.error.BusinessException;
+import com.goafanti.common.model.RestrictProject;
 import com.goafanti.core.mybatis.BaseMybatisDao;
 import com.goafanti.core.shiro.token.TokenManager;
+import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.util.Date;
 
+@Service
 public class RestrictProjectServiceImpl extends BaseMybatisDao<RestrictProjectMapper> implements RestrictProjectService {
     @Resource
     private RestrictProjectMapper restrictProjectMapper;
@@ -15,7 +20,18 @@ public class RestrictProjectServiceImpl extends BaseMybatisDao<RestrictProjectMa
     public int add(InputRestrictProject in) {
         String aid = TokenManager.getAdminId();
         in.setAid(aid);
-
-        return restrictProjectMapper.insertSelective(in);
+        in.setType(1);
+        in.setLockTime(new Date());
+        RestrictProject use = restrictProjectMapper.selectByPid(in);
+        if (use != null && use.getType() != 0){
+            throw new BusinessException("该项目已存在");
+        }
+        if(use ==null){
+            restrictProjectMapper.insertSelective(in);
+        }else if (use.getType() == 0){
+            in.setId(use.getId());
+            restrictProjectMapper.updateByPrimaryKeySelective(in);
+        }
+        return 1;
     }
 }

+ 2 - 0
src/main/java/com/goafanti/common/dao/RestrictProjectMapper.java

@@ -1,5 +1,6 @@
 package com.goafanti.common.dao;
 
+import com.goafanti.business.bo.InputRestrictProject;
 import com.goafanti.common.model.RestrictProject;
 
 /**
@@ -22,4 +23,5 @@ public interface RestrictProjectMapper {
 
     int updateByPrimaryKey(RestrictProject record);
 
+    RestrictProject selectByPid(InputRestrictProject in);
 }

+ 9 - 0
src/main/java/com/goafanti/common/mapper/RestrictProjectMapper.xml

@@ -28,6 +28,7 @@
         where  id = #{id,jdbcType=INTEGER} 
     </select>
 
+
     <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
         delete from restrict_project
         where  id = #{id,jdbcType=INTEGER} 
@@ -103,4 +104,12 @@
             create_time =  #{createTime,jdbcType=TIMESTAMP}
         where   id = #{id,jdbcType=INTEGER} 
     </update>
+
+    <select id="selectByPid" resultMap="BaseResultMap">
+        select
+        <include refid="Base_Column_List" />
+        from restrict_project
+        where  pid = #{pid,jdbcType=VARCHAR}
+        and aid = #{aid,jdbcType=VARCHAR}
+    </select>
 </mapper>