From aaf524ee709552de91886a00d729e122b021928e Mon Sep 17 00:00:00 2001 From: tangw Date: Tue, 11 Nov 2025 20:01:04 +0800 Subject: [PATCH] reg_dict --- sql/lis8.0/updatedb_lis8.0.sql | 24 +++ .../controller/dict/RegDictController.java | 107 +++++++++++++ .../czlis/transitPF/mapper/RegDictMapper.java | 81 ++++++++++ .../com/czlis/transitPF/pojo/RegDict.java | 45 ++++++ .../transitPF/service/RegDictService.java | 87 +++++++++++ .../service/impl/RegDictServiceImpl.java | 146 ++++++++++++++++++ .../main/resources/mapper/RegDictMapper.xml | 122 +++++++++++++++ 7 files changed, 612 insertions(+) create mode 100644 transitPF/src/main/java/com/czlis/transitPF/controller/dict/RegDictController.java create mode 100644 transitPF/src/main/java/com/czlis/transitPF/mapper/RegDictMapper.java create mode 100644 transitPF/src/main/java/com/czlis/transitPF/pojo/RegDict.java create mode 100644 transitPF/src/main/java/com/czlis/transitPF/service/RegDictService.java create mode 100644 transitPF/src/main/java/com/czlis/transitPF/service/impl/RegDictServiceImpl.java create mode 100644 transitPF/src/main/resources/mapper/RegDictMapper.xml diff --git a/sql/lis8.0/updatedb_lis8.0.sql b/sql/lis8.0/updatedb_lis8.0.sql index 5e7e922..86d6d1f 100644 --- a/sql/lis8.0/updatedb_lis8.0.sql +++ b/sql/lis8.0/updatedb_lis8.0.sql @@ -296,3 +296,27 @@ ALTER TABLE [dbo].[reg_itemclass] ADD DEFAULT (1) FOR [itemclass_printcnt] ALTER TABLE [dbo].[reg_itemclass] ADD DEFAULT ('') FOR [update_by] ALTER TABLE [dbo].[reg_itemclass] ADD DEFAULT (NULL) FOR [remark] end + +if not exists(SELECT 1 FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'req_dict') +begin +CREATE TABLE [dbo].[reg_dict]( + [dict_id] [bigint] IDENTITY(1,1) NOT NULL, + [dict_type] [varchar](20) NOT NULL, + [dict_code] [varchar](64) NOT NULL, + [dict_name] [varchar](250) NOT NULL, + [dict_sort] [int] NOT NULL, + [status] [char](1) NOT NULL, + [create_by] [varchar](64) NULL, + [create_time] [datetime] NULL, + [update_by] [varchar](64) NULL, + [update_time] [datetime] NULL, + [remark] [varchar](500) NULL, + PRIMARY KEY CLUSTERED +( +[dict_id] ASC +)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] + ) ON [PRIMARY] +ALTER TABLE [dbo].[reg_dict] ADD DEFAULT ('') FOR [create_by] +ALTER TABLE [dbo].[reg_dict] ADD DEFAULT ('') FOR [update_by] +ALTER TABLE [dbo].[reg_dict] ADD DEFAULT (NULL) FOR [remark] +end \ No newline at end of file diff --git a/transitPF/src/main/java/com/czlis/transitPF/controller/dict/RegDictController.java b/transitPF/src/main/java/com/czlis/transitPF/controller/dict/RegDictController.java new file mode 100644 index 0000000..d6b7ff2 --- /dev/null +++ b/transitPF/src/main/java/com/czlis/transitPF/controller/dict/RegDictController.java @@ -0,0 +1,107 @@ +package com.czlis.transitPF.controller.dict; + +import com.czlis.common.annotation.Log; +import com.czlis.common.core.controller.BaseController; +import com.czlis.common.core.domain.AjaxResult; +import com.czlis.common.core.page.TableDataInfo; +import com.czlis.common.enums.BusinessType; +import com.czlis.common.utils.poi.ExcelUtil; +import com.czlis.transitPF.pojo.RegDict; +import com.czlis.transitPF.service.RegDictService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import javax.servlet.http.HttpServletResponse; +import java.util.List; + +@Api(tags = "区域检验中心-常用字典管理") +@RestController +@RequestMapping("/transitdict/regdict") +@Slf4j +public class RegDictController extends BaseController { + @Autowired + private RegDictService regDictService; + /** + * 获取字典列表 + */ + @ApiOperation("获取字典列表") + @GetMapping("/list") + public TableDataInfo list(RegDict post) { + startPage(); + List list = regDictService.selectDictList(post); + return getDataTable(list); + } + @ApiOperation("字典导出") + @Log(title = "字典导出", businessType = BusinessType.EXPORT) + @PostMapping("/export") + public void export(HttpServletResponse response, RegDict post) { + List list = regDictService.selectDictList(post); + ExcelUtil util = new ExcelUtil<>(RegDict.class); + util.exportExcel(response, list, "字典数据"); + } + + /** + * 根据字典编号获取详细信息 + */ + @ApiOperation("获取详细信息") + @GetMapping(value = "/{dictId}") + public AjaxResult getInfo(@PathVariable Long dictId) { + return success(regDictService.selectDictById(dictId)); + } + + /** + * 新增字典 + */ + @ApiOperation("新增字典") + @Log(title = "字典管理", businessType = BusinessType.INSERT) + @PostMapping + public AjaxResult add(@Validated @RequestBody RegDict post) { + if (!regDictService.checkDictNameUnique(post)) { + return error("新增字典'" + post.getDictName() + "'失败,字典名称已存在"); + } else if (!regDictService.checkDictCodeUnique(post)) { + return error("新增字典'" + post.getDictName() + "'失败,字典编码已存在"); + } + post.setCreateBy(getUsername()); + return toAjax(regDictService.insertDict(post)); + } + + /** + * 修改字典 + */ + @ApiOperation("修改字典") + @Log(title = "字典管理", businessType = BusinessType.UPDATE) + @PutMapping + public AjaxResult edit(@Validated @RequestBody RegDict post) { + if (!regDictService.checkDictNameUnique(post)) { + return error("修改字典'" + post.getDictName() + "'失败,字典名称已存在"); + } else if (!regDictService.checkDictCodeUnique(post)) { + return error("修改字典'" + post.getDictName() + "'失败,字典编码已存在"); + } + post.setUpdateBy(getUsername()); + return toAjax(regDictService.updateDict(post)); + } + + /** + * 删除字典 + */ + @ApiOperation("删除字典") + @Log(title = "字典管理", businessType = BusinessType.DELETE) + @DeleteMapping("/{dictIds}") + public AjaxResult remove(@PathVariable Long[] dictIds) { + return toAjax(regDictService.deleteDictByIds(dictIds)); + } + + /** + * 获取字典选择框列表 + */ + @ApiOperation("获取字典选择框列表") + @GetMapping("/optionselect") + public AjaxResult optionselect() { + List posts = regDictService.selectDictAll(); + return success(posts); + } +} diff --git a/transitPF/src/main/java/com/czlis/transitPF/mapper/RegDictMapper.java b/transitPF/src/main/java/com/czlis/transitPF/mapper/RegDictMapper.java new file mode 100644 index 0000000..9e56a36 --- /dev/null +++ b/transitPF/src/main/java/com/czlis/transitPF/mapper/RegDictMapper.java @@ -0,0 +1,81 @@ +package com.czlis.transitPF.mapper; + +import com.czlis.transitPF.pojo.RegDict; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +public interface RegDictMapper { + /** + * 查询字典数据集合 + * + * @param Dict 字典信息 + * @return 字典数据集合 + */ + List selectDictList(RegDict Dict); + + /** + * 查询所有字典 + * + * @return 字典列表 + */ + List selectDictAll(); + + /** + * 通过字典ID查询字典信息 + * + * @param DictId 字典ID + * @return 角色对象信息 + */ + RegDict selectDictById(Long DictId); + + + /** + * 删除字典信息 + * + * @param DictId 字典ID + * @return 结果 + */ + int deleteDictById(Long DictId); + + /** + * 批量删除字典信息 + * + * @param DictIds 需要删除的字典ID + * @return 结果 + */ + int deleteDictByIds(Long[] DictIds); + + /** + * 修改字典信息 + * + * @param Dict 字典信息 + * @return 结果 + */ + int updateDict(RegDict Dict); + + /** + * 新增字典信息 + * + * @param Dict 字典信息 + * @return 结果 + */ + int insertDict(RegDict Dict); + + /** + * 校验字典名称 + * + * @param dictName 字典名称 + * @param dictType 类别 + * @return 结果 + */ + RegDict checkDictNameUnique(@Param("dictName") String dictName,@Param("dictType") String dictType); + + /** + * 校验字典编码 + * + * @param DictCode 字典编码 + * @return 结果 + */ + RegDict checkDictCodeUnique(@Param("dictCode") String DictCode,@Param("dictType") String dictType); +} diff --git a/transitPF/src/main/java/com/czlis/transitPF/pojo/RegDict.java b/transitPF/src/main/java/com/czlis/transitPF/pojo/RegDict.java new file mode 100644 index 0000000..1877256 --- /dev/null +++ b/transitPF/src/main/java/com/czlis/transitPF/pojo/RegDict.java @@ -0,0 +1,45 @@ +package com.czlis.transitPF.pojo; + +import com.czlis.common.annotation.Excel; +import com.czlis.common.core.domain.BaseEntity; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@AllArgsConstructor +@NoArgsConstructor +public class RegDict extends BaseEntity { + private static final long serialVersionUID = 1L; + /** + * 字典序号 + */ + @Excel(name = "字典序号", cellType = Excel.ColumnType.NUMERIC) + private Long dictId; + /** + * 字典编码 + */ + @Excel(name = "字典类别") + private String dictType; + /** + * 字典编码 + */ + @Excel(name = "字典编码") + private String dictCode; + + /** + * 字典名称 + */ + @Excel(name = "字典名称") + private String dictName; + /** + * 字典排序 + */ + @Excel(name = "排序") + private Long dictSort; + /** + * 状态(0正常 1停用) + */ + @Excel(name = "状态", readConverterExp = "0=正常,1=停用") + private String status; +} diff --git a/transitPF/src/main/java/com/czlis/transitPF/service/RegDictService.java b/transitPF/src/main/java/com/czlis/transitPF/service/RegDictService.java new file mode 100644 index 0000000..06f3944 --- /dev/null +++ b/transitPF/src/main/java/com/czlis/transitPF/service/RegDictService.java @@ -0,0 +1,87 @@ +package com.czlis.transitPF.service; + +import com.czlis.transitPF.pojo.RegDict; + +import java.util.List; + +public interface RegDictService { + /** + * 查询字典信息集合 + * + * @param Dict 字典信息 + * @return 字典列表 + */ + List selectDictList(RegDict Dict); + + /** + * 查询所有字典 + * + * @return 字典列表 + */ + List selectDictAll(); + + /** + * 通过字典ID查询字典信息 + * + * @param DictId 字典ID + * @return 角色对象信息 + */ + RegDict selectDictById(Long DictId); + + + /** + * 校验字典名称 + * + * @param Dict 字典信息 + * @return 结果 + */ + boolean checkDictNameUnique(RegDict Dict); + + /** + * 校验字典编码 + * + * @param Dict 字典信息 + * @return 结果 + */ + boolean checkDictCodeUnique(RegDict Dict); + + /** + * 通过字典ID查询字典使用数量 + * + * @param DictId 字典ID + * @return 结果 + */ + int countUserDictById(Long DictId); + + /** + * 删除字典信息 + * + * @param DictId 字典ID + * @return 结果 + */ + int deleteDictById(Long DictId); + + /** + * 批量删除字典信息 + * + * @param DictIds 需要删除的字典ID + * @return 结果 + */ + int deleteDictByIds(Long[] DictIds); + + /** + * 新增保存字典信息 + * + * @param Dict 字典信息 + * @return 结果 + */ + int insertDict(RegDict Dict); + + /** + * 修改保存字典信息 + * + * @param Dict 字典信息 + * @return 结果 + */ + int updateDict(RegDict Dict); +} diff --git a/transitPF/src/main/java/com/czlis/transitPF/service/impl/RegDictServiceImpl.java b/transitPF/src/main/java/com/czlis/transitPF/service/impl/RegDictServiceImpl.java new file mode 100644 index 0000000..41593d2 --- /dev/null +++ b/transitPF/src/main/java/com/czlis/transitPF/service/impl/RegDictServiceImpl.java @@ -0,0 +1,146 @@ +package com.czlis.transitPF.service.impl; + +import com.czlis.common.constant.UserConstants; +import com.czlis.common.exception.ServiceException; +import com.czlis.common.utils.StringUtils; +import com.czlis.transitPF.mapper.RegDictMapper; +import com.czlis.transitPF.pojo.RegDict; +import com.czlis.transitPF.service.RegDictService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +@Slf4j +public class RegDictServiceImpl implements RegDictService { + @Autowired + RegDictMapper dictMapper; + + /** + * 查询字典信息集合 + * + * @param Dict 字典信息 + * @return 字典信息集合 + */ + @Override + public List selectDictList(RegDict Dict) { + return dictMapper.selectDictList(Dict); + } + + /** + * 查询所有字典 + * + * @return 字典列表 + */ + @Override + public List selectDictAll() { + return dictMapper.selectDictAll(); + } + + /** + * 通过字典ID查询字典信息 + * + * @param DictId 字典ID + * @return 角色对象信息 + */ + @Override + public RegDict selectDictById(Long DictId) { + return dictMapper.selectDictById(DictId); + } + + + /** + * 校验字典名称是否唯一 + * + * @param Dict 字典信息 + * @return 结果 + */ + @Override + public boolean checkDictNameUnique(RegDict Dict) { + Long DictId = StringUtils.isNull(Dict.getDictId()) ? -1L : Dict.getDictId(); + RegDict info = dictMapper.checkDictNameUnique(Dict.getDictName(),Dict.getDictType()); + if (StringUtils.isNotNull(info) && info.getDictId().longValue() != DictId.longValue()) { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } + + /** + * 校验字典编码是否唯一 + * + * @param Dict 字典信息 + * @return 结果 + */ + @Override + public boolean checkDictCodeUnique(RegDict Dict) { + Long DictId = StringUtils.isNull(Dict.getDictId()) ? -1L : Dict.getDictId(); + RegDict info = dictMapper.checkDictCodeUnique(Dict.getDictCode(),Dict.getDictType()); + if (StringUtils.isNotNull(info) && info.getDictId().longValue() != DictId.longValue()) { + return UserConstants.NOT_UNIQUE; + } + return UserConstants.UNIQUE; + } + + /** + * 通过字典ID查询字典使用数量 + * + * @param DictId 字典ID + * @return 结果 + */ + @Override + public int countUserDictById(Long DictId) { + return 0;//dictMapper.countUserDictById(DictId); + } + + /** + * 删除字典信息 + * + * @param DictId 字典ID + * @return 结果 + */ + @Override + public int deleteDictById(Long DictId) { + return dictMapper.deleteDictById(DictId); + } + + /** + * 批量删除字典信息 + * + * @param DictIds 需要删除的字典ID + * @return 结果 + */ + @Override + public int deleteDictByIds(Long[] DictIds) { + for (Long DictId : DictIds) { + RegDict Dict = selectDictById(DictId); + if (countUserDictById(DictId) > 0) { + throw new ServiceException(String.format("%1$s已分配,不能删除", Dict.getDictName())); + } + } + return dictMapper.deleteDictByIds(DictIds); + } + + /** + * 新增保存字典信息 + * + * @param Dict 字典信息 + * @return 结果 + */ + @Override + public int insertDict(RegDict Dict) { + return dictMapper.insertDict(Dict); + } + + /** + * 修改保存字典信息 + * + * @param Dict 字典信息 + * @return 结果 + */ + @Override + public int updateDict(RegDict Dict) { + return dictMapper.updateDict(Dict); + } +} diff --git a/transitPF/src/main/resources/mapper/RegDictMapper.xml b/transitPF/src/main/resources/mapper/RegDictMapper.xml new file mode 100644 index 0000000..80a6c76 --- /dev/null +++ b/transitPF/src/main/resources/mapper/RegDictMapper.xml @@ -0,0 +1,122 @@ + + + + + + + + + + + + + + + + + + + select dict_id,dict_type, dict_code, dict_name, dict_Sort, status, create_by, create_time, remark + from Reg_Dict + + + + + + + + + + + + + + + + update Reg_Dict + + dict_type = #{dictType}, + dict_code = #{dictCode}, + dict_name = #{dictName}, + dict_Sort = #{dictSort}, + status = #{status}, + remark = #{remark}, + update_by = #{updateBy}, + update_time = getdate() + + where dict_id = #{dictId} + + + + insert into Reg_Dict( + dict_id, + dict_type, + dict_code, + dict_name, + dict_Sort, + status, + remark, + create_by, + create_time + )values( + #{dictId}, + #{dictType}, + #{dictCode}, + #{dictName}, + #{dictSort}, + #{status}, + #{remark}, + #{createBy}, + getdate() + ) + + + + delete from Reg_Dict where dict_id = #{dictId} + + + + delete from Reg_Dict where dict_id in + + #{dictId} + + + + + \ No newline at end of file