Browse Source

新增最小公出时长

anderx 2 years ago
parent
commit
decde2a331

+ 22 - 9
src/main/java/com/goafanti/admin/controller/AdminDepartmentApiController.java

@@ -2,20 +2,17 @@ package com.goafanti.admin.controller;
 
 
 
-import javax.annotation.Resource;
-
-
-
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-
 import com.goafanti.admin.service.DepartmentService;
 import com.goafanti.common.bo.Result;
 import com.goafanti.common.constant.ErrorConstants;
 import com.goafanti.common.controller.CertifyApiController;
 import com.goafanti.common.model.WorkingHours;
 import com.goafanti.common.utils.StringUtils;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+import javax.annotation.Resource;
 
 @Controller
 @RequestMapping(value = "/api/admin/department")
@@ -36,7 +33,7 @@ public class AdminDepartmentApiController extends CertifyApiController {
 			res.getError().add(buildError(ErrorConstants.PARAM_ERROR, "", ""));
 			return res;
 		}
-		if (departmentService.checkWorkingHoursType(in.getType())) {
+		if (departmentService.checkWorkingHoursType(in)) {
 			res.getError().add(buildError(ErrorConstants.PARAM_BEING_ERROR, "", "分类"));
 			return res;
 		}
@@ -44,6 +41,22 @@ public class AdminDepartmentApiController extends CertifyApiController {
 		return res;
 	}
 
+
+	/**
+	 * 新增工作时间
+	 */
+	@RequestMapping(value = "/workingHours/update", method = RequestMethod.POST)
+	public Result update(WorkingHours in) {
+		Result res = new Result();
+
+		if (departmentService.checkWorkingHoursType(in)) {
+			res.getError().add(buildError(ErrorConstants.PARAM_BEING_ERROR, "", "分类"));
+			return res;
+		}
+		res.setData(departmentService.updateWorkingHours(in));
+		return res;
+	}
+
 	/**
 	 * 删除工作时间
 	 */

+ 2 - 3
src/main/java/com/goafanti/admin/service/DepartmentService.java

@@ -1,6 +1,5 @@
 package com.goafanti.admin.service;
 
-import com.goafanti.admin.bo.DepartmentComboBox;
 import com.goafanti.common.model.Department;
 import com.goafanti.common.model.WorkingHours;
 
@@ -17,7 +16,7 @@ public interface DepartmentService {
 
 	Object getWorkingHours(String depId);
 
-	boolean checkWorkingHoursType(Integer type);
+	boolean checkWorkingHoursType(WorkingHours type);
 
 	boolean checkDepWorkingHouresType(Integer id);
 
@@ -54,5 +53,5 @@ public interface DepartmentService {
 	List<String> comparePermissions(List<String> aDep, String deps);
 
 
-
+	int updateWorkingHours(WorkingHours in);
 }

+ 26 - 16
src/main/java/com/goafanti/admin/service/impl/DepartmentServiceImpl.java

@@ -1,24 +1,18 @@
 package com.goafanti.admin.service.impl;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
 import com.alibaba.fastjson.JSON;
-import com.goafanti.admin.bo.DepartmentComboBox;
-import com.goafanti.common.constant.AFTConstants;
-import com.goafanti.common.dao.AdminMapper;
+import com.goafanti.admin.service.DepartmentService;
 import com.goafanti.common.dao.DepartmentMapper;
+import com.goafanti.common.dao.WorkingHoursMapper;
 import com.goafanti.common.model.Department;
+import com.goafanti.common.model.WorkingHours;
+import com.goafanti.core.mybatis.BaseMybatisDao;
 import com.goafanti.core.shiro.token.TokenManager;
-import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
-import com.goafanti.admin.service.DepartmentService;
-import com.goafanti.common.dao.WorkingHoursMapper;
-import com.goafanti.common.model.WorkingHours;
-import com.goafanti.core.mybatis.BaseMybatisDao;
+import java.util.ArrayList;
+import java.util.List;
 
 @Service
 public class DepartmentServiceImpl extends BaseMybatisDao<WorkingHoursMapper> implements DepartmentService {
@@ -35,6 +29,11 @@ public class DepartmentServiceImpl extends BaseMybatisDao<WorkingHoursMapper> im
 	}
 
 	@Override
+	public int updateWorkingHours(WorkingHours in) {
+		return workingHoursMapper.updateByPrimaryKeySelective(in);
+	}
+
+	@Override
 	public int deleteWorkingHours(Integer id) {
 		return workingHoursMapper.deleteByPrimaryKey(id);
 	}
@@ -50,10 +49,20 @@ public class DepartmentServiceImpl extends BaseMybatisDao<WorkingHoursMapper> im
 	}
 
 	@Override
-	public boolean checkWorkingHoursType(Integer type) {
-		int i=workingHoursMapper.getTypeCount(type);
-		if(i>0) {
-			return true;
+	public boolean checkWorkingHoursType(WorkingHours in) {
+		if (in.getType()!=null){
+			List<WorkingHours> typeCount = workingHoursMapper.getTypeCount(in.getType());
+			if(typeCount.size()>1) {
+				return true;
+			}else {
+				if (in.getId()!=null){
+					for (WorkingHours e : typeCount) {
+						if (e.getId().equals(in.getId())){
+							return true;
+						}
+					}
+				}
+			}
 		}
 		return false;
 	}
@@ -123,6 +132,7 @@ public class DepartmentServiceImpl extends BaseMybatisDao<WorkingHoursMapper> im
 
 
 
+
 	public List<String> comparePermissions(List<String> aDep, List<String> input) {
 		List<String> myAll=new ArrayList<>();
 		for (String s : aDep) {

+ 1 - 1
src/main/java/com/goafanti/common/dao/WorkingHoursMapper.java

@@ -23,7 +23,7 @@ public interface WorkingHoursMapper {
 
     WorkingHours selectBydepId(@Param("depId")String depId);
 
-    int getTypeCount(Integer type);
+    List<WorkingHours> getTypeCount(Integer type);
 
     int getDepTypeCount(Integer id);
 }

+ 4 - 2
src/main/java/com/goafanti/common/mapper/WorkingHoursMapper.xml

@@ -143,8 +143,10 @@
     from department d  left join working_hours a on d.working_hours_type =a.type
     where d.id = #{depId}
   </select>
-  <select id="getTypeCount" resultType="java.lang.Integer">
-  select count(*) from working_hours where type= #{type}
+  <select id="getTypeCount" resultMap="BaseResultMap">
+    select
+    <include refid="Base_Column_List" />
+  from working_hours where type= #{type}
   </select>
 
   <select id="getDepTypeCount" resultType="java.lang.Integer">