123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- 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.dao.his.dictionary.ZdHealthEducationTypeDao;
- import thyyxxk.webserver.entity.ResultVo;
- import thyyxxk.webserver.entity.dictionary.CodeName;
- import thyyxxk.webserver.entity.dictionary.ZdHealthEducation;
- import thyyxxk.webserver.entity.dictionary.ZdHealthEducationType;
- 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;
- private final ZdHealthEducationTypeDao zdHealthEducationTypeDao;
- public ServiceNumberService(ServiceNumberDao dao, ZdHealthEducationDao healthEducationDao,
- ZdHealthEducationTypeDao zdHealthEducationTypeDao) {
- this.dao = dao;
- this.healthEducationDao = healthEducationDao;
- this.zdHealthEducationTypeDao = zdHealthEducationTypeDao;
- }
- 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, "删除健康教育字典失败!");
- }
- }
- public ResultVo<List<ZdHealthEducationType>> selectHeType(){
- return ResultVoUtil.success(zdHealthEducationTypeDao.selectHeType());
- }
- public ResultVo<Map<String, Object>> saveHeType(ZdHealthEducationType zdHealthEducationType){
- if(null == zdHealthEducationType || zdHealthEducationType.getCode() == null){
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "健康教育类型信息不存在,请检查!");
- }
- Map<String, Object> resultMap = new HashMap<>();
- String code = zdHealthEducationType.getCode();
- ZdHealthEducationType type = zdHealthEducationTypeDao.selectHeTypeByCode(code);
- int num;
- try{
- if(null != type){
- num = zdHealthEducationTypeDao.updateHeTypeByCode(zdHealthEducationType);
- } else {
- num = zdHealthEducationTypeDao.insert(zdHealthEducationType);
- }
- 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>> delHeTypeByCode(String code) {
- if (StringUtil.isBlank(code)) {
- return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "没有健康教育类型编码,请检查!");
- }
- Map<String, Object> resultMap = new HashMap<>();
- try{
- int num = zdHealthEducationTypeDao.deleteHeTypeByCode(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, "删除健康教育类型失败!");
- }
- }
- }
|