Browse Source

新增健康教育字典

hsh 1 year ago
parent
commit
3b2541b70f

+ 57 - 0
src/main/java/thyyxxk/webserver/controller/dictionary/ServiceNumberController.java

@@ -0,0 +1,57 @@
+package thyyxxk.webserver.controller.dictionary;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+import thyyxxk.webserver.entity.ResultVo;
+import thyyxxk.webserver.entity.dictionary.CodeName;
+import thyyxxk.webserver.entity.dictionary.ZdHealthEducation;
+import thyyxxk.webserver.service.dictionary.ServiceNumberService;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @ClassName HealthEducationController
+ * @Author hsh
+ * @Date 2024/3/22 8:51
+ * @Version 1.0
+ * @Description 服务号相关字典
+ **/
+@RestController
+@RequestMapping("/serviceNumber")
+public class ServiceNumberController {
+
+    private final ServiceNumberService service;
+
+    @Autowired
+    public ServiceNumberController(ServiceNumberService service) {
+        this.service = service;
+    }
+
+    @GetMapping("/selectServiceNumberDict")
+    public ResultVo<Map<String, List<CodeName>>> selectServiceNumberDict(){
+        return service.selectServiceNumberDict();
+    }
+
+    @GetMapping("/selectHealthEducation")
+    public ResultVo<List<ZdHealthEducation>> selectHealthEducation(){
+        return service.selectHealthEducation();
+    }
+
+    @PostMapping("/saveHealthEducation")
+    public ResultVo<Map<String, Object>> saveHealthEducation(@RequestBody @Validated ZdHealthEducation zdHealthEducation){
+        return service.saveHealthEducation(zdHealthEducation);
+    }
+
+    @GetMapping("/delHealthEducationByCode")
+    public ResultVo<Map<String, Object>> delHealthEducationByCode(@RequestParam("code") String code){
+        return service.delHealthEducationByCode(code);
+    }
+
+}

+ 15 - 0
src/main/java/thyyxxk/webserver/dao/his/dictionary/ServiceNumberDao.java

@@ -0,0 +1,15 @@
+package thyyxxk.webserver.dao.his.dictionary;
+
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Select;
+import thyyxxk.webserver.entity.dictionary.CodeName;
+
+import java.util.List;
+
+@Mapper
+public interface ServiceNumberDao {
+
+    @Select(" select * from zd_health_education_type ")
+    List<CodeName> selectHealthEducationType();
+
+}

+ 54 - 0
src/main/java/thyyxxk/webserver/dao/his/dictionary/ZdHealthEducationDao.java

@@ -0,0 +1,54 @@
+package thyyxxk.webserver.dao.his.dictionary;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Delete;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+import org.apache.ibatis.annotations.Select;
+import org.apache.ibatis.annotations.Update;
+import thyyxxk.webserver.entity.dictionary.ZdHealthEducation;
+
+import java.util.List;
+
+@Mapper
+public interface ZdHealthEducationDao extends BaseMapper<ZdHealthEducation> {
+
+    @Select(" select * from zd_health_education order by sort_no ")
+    List<ZdHealthEducation> selectHealthEducation();
+
+    @Select(" select * from zd_health_education where code = #{code} ")
+    ZdHealthEducation selectHealthEducationByCode(@Param("code") String code);
+
+    @Update("<script>" +
+            "update zd_health_education " +
+            "<trim prefix=\"set\" suffixOverrides=\",\">" +
+            "<if test=\"code != null and code != '' \">" +
+            "code = #{code}, " +
+            "</if>" +
+            "<if test=\"name != null and name != '' \">" +
+            "name = #{name}, " +
+            "</if>" +
+            "<if test=\"sortNo != null and sortNo != '' \">" +
+            "sort_no = #{sortNo}, " +
+            "</if>" +
+            "<if test=\"url != null and url != '' \">" +
+            "url = #{url}, " +
+            "</if>" +
+            "<if test=\"type != null and type != '' \">" +
+            "type = #{type}, " +
+            "</if>" +
+            "<if test=\"typeName != null and typeName != '' \">" +
+            "type_name = #{typeName}, " +
+            "</if>" +
+            "</trim>" +
+            "where code = #{code} " +
+            "</script>")
+    int updateHealthEducationByCode(ZdHealthEducation zdHealthEducation);
+
+    @Delete(" delete from zd_health_education where code = #{code} ")
+    int deleteHealthEducationByCode(@Param("code") String code);
+
+    @Select(" select max(code) from zd_health_education ")
+    String selectMaxCodeOfHealthEducation();
+
+}

+ 30 - 0
src/main/java/thyyxxk/webserver/entity/dictionary/ZdHealthEducation.java

@@ -0,0 +1,30 @@
+package thyyxxk.webserver.entity.dictionary;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @ClassName ZdHealthEducation
+ * @Author hsh
+ * @Date 2024/3/22 9:00
+ * @Version 1.0
+ * @Description TODO
+ **/
+@Data
+@TableName(value = "zd_health_education")
+public class ZdHealthEducation implements Serializable {
+
+    private static final long serialVersionUID = -1L;
+    @TableId(value = "code", type = IdType.NONE)
+    private String code;
+    private String name;
+    private String sortNo;
+    private String url;
+    private String type;
+    private String typeName;
+
+}

+ 112 - 0
src/main/java/thyyxxk/webserver/service/dictionary/ServiceNumberService.java

@@ -0,0 +1,112 @@
+package thyyxxk.webserver.service.dictionary;
+
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+import thyyxxk.webserver.config.exception.ExceptionEnum;
+import thyyxxk.webserver.dao.his.dictionary.ServiceNumberDao;
+import thyyxxk.webserver.dao.his.dictionary.ZdHealthEducationDao;
+import thyyxxk.webserver.entity.ResultVo;
+import thyyxxk.webserver.entity.dictionary.CodeName;
+import thyyxxk.webserver.entity.dictionary.ZdHealthEducation;
+import thyyxxk.webserver.utils.ResultVoUtil;
+import thyyxxk.webserver.utils.StringUtil;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+
+/**
+ * @ClassName ServiceNumberService
+ * @Author hsh
+ * @Date 2024/3/22 8:54
+ * @Version 1.0
+ * @Description 服务号相关字典
+ **/
+@Service
+@Slf4j
+public class ServiceNumberService {
+
+    private final ServiceNumberDao dao;
+
+    private final ZdHealthEducationDao healthEducationDao;
+
+    public ServiceNumberService(ServiceNumberDao dao, ZdHealthEducationDao healthEducationDao) {
+        this.dao = dao;
+        this.healthEducationDao = healthEducationDao;
+    }
+
+    public ResultVo<Map<String, List<CodeName>>> selectServiceNumberDict(){
+        Map<String, List<CodeName>> map = new HashMap<>();
+        List<CodeName> list = dao.selectHealthEducationType();
+        map.put("HEType", list);
+        return ResultVoUtil.success(map);
+    }
+
+    public ResultVo<List<ZdHealthEducation>> selectHealthEducation(){
+        return ResultVoUtil.success(healthEducationDao.selectHealthEducation());
+    }
+
+    public ResultVo<Map<String, Object>> saveHealthEducation(ZdHealthEducation zdHealthEducation){
+
+        if(null == zdHealthEducation){
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "健康教育字典信息不存在,请检查!");
+        }
+
+        Map<String, Object> resultMap = new HashMap<>();
+        String code = zdHealthEducation.getCode();
+        ZdHealthEducation healthEducation = healthEducationDao.selectHealthEducationByCode(code);
+        // 设置健康教育类型名称
+        List<CodeName> he = dao.selectHealthEducationType();
+        Optional<CodeName> s = he.stream().filter(codeName -> codeName.getCode().equals(zdHealthEducation.getType())).findFirst();
+        s.ifPresent(codeName -> zdHealthEducation.setTypeName(codeName.getName()));
+        int num;
+        try{
+            if(null != healthEducation){
+                num = healthEducationDao.updateHealthEducationByCode(zdHealthEducation);
+            } else {
+                String maxCode = healthEducationDao.selectMaxCodeOfHealthEducation();
+                String newCode;
+                if(maxCode.startsWith("0")){
+                    int number = Integer.parseInt(maxCode.replace("0", ""));
+                    if(number == 9){
+                        newCode = (number + 1) + "";
+                    } else {
+                        newCode = "0" + (number + 1);
+                    }
+                } else {
+                    int number = Integer.parseInt(maxCode);
+                    newCode = (number + 1) + "";
+                }
+                zdHealthEducation.setCode(newCode);
+                num = healthEducationDao.insert(zdHealthEducation);
+            }
+            if(num == 0){
+                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存健康教育字典信息失败!");
+            }
+            resultMap.put("cg", "保存健康教育字典信息成功!");
+            return ResultVoUtil.success(resultMap);
+        } catch(Exception e){
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "保存健康教育字典信息失败!");
+        }
+    }
+
+    public ResultVo<Map<String, Object>> delHealthEducationByCode(String code) {
+        if (StringUtil.isBlank(code)) {
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有健康教育字典编码,请检查!");
+        }
+
+        Map<String, Object> resultMap = new HashMap<>();
+        try{
+            int num = healthEducationDao.deleteHealthEducationByCode(code);
+            if(num == 0){
+                return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除健康教育字典失败!");
+            }
+            resultMap.put("cg", "删除健康教育字典成功!");
+            return ResultVoUtil.success(resultMap);
+        } catch(Exception e){
+            return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "删除健康教育字典失败!");
+        }
+    }
+
+}