| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328 |
- package com.ydtech.modules.admin.controller;
- import com.ydtech.config.DictEnumConfig;
- import com.ydtech.constants.enums.dict.DictionaryManagement;
- import com.ydtech.core.page.BaseController;
- import com.ydtech.core.page.HttpResult;
- import com.ydtech.core.page.PageRequest;
- import com.ydtech.modules.admin.model.SysAccount;
- import com.ydtech.modules.admin.model.SysDict;
- import com.ydtech.modules.admin.model.SysDictType;
- import com.ydtech.modules.admin.model.SysUser;
- import com.ydtech.modules.admin.service.SysAccountService;
- import com.ydtech.modules.admin.service.SysDeptService;
- import com.ydtech.modules.admin.service.SysDictService;
- import com.ydtech.modules.admin.service.SysDictTypeService;
- import com.ydtech.modules.admin.vo.TreeSysDeptVO;
- import com.ydtech.modules.esm.model.EsmInsCompany;
- import com.ydtech.modules.esm.model.EsmProduct;
- import com.ydtech.modules.esm.service.EsmInsCompanyService;
- import com.ydtech.modules.esm.service.EsmProductService;
- import com.ydtech.security.utils.JwtTokenUtils;
- import com.ydtech.utils.StringUtils;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import org.apache.commons.collections4.list.TreeList;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.util.CollectionUtils;
- import org.springframework.web.bind.annotation.*;
- import javax.servlet.http.HttpServletRequest;
- import java.util.*;
- /**
- * 字典控制器
- *
- * @author Yasepix
- * @date Oct 29, 2018
- */
- @Api(tags = "字典管理")
- @RestController
- @RequestMapping("dict")
- public class SysDictController extends BaseController {
- @Autowired
- private SysDictService sysDictService;
- @Autowired
- private SysDictTypeService sysDictTypeService;
- @Autowired
- private SysDeptService sysDeptService;
- @Autowired
- private EsmInsCompanyService esmInsCompanyService;
- @Autowired
- private EsmProductService esmProductService;
- @Autowired
- private SysAccountService sysAccountService;
- // @PreAuthorize("hasAuthority('sys:dict:add') AND hasAuthority('sys:dict:edit')")
- // @PostMapping(value="/save")
- // public HttpResult save(@RequestBody SysDict record) {
- // return HttpResult.ok(sysDictService.save(record));
- // }
- // @PreAuthorize("hasAuthority('sys:dict:add')")
- @PostMapping(value = "/add")
- public HttpResult add(@RequestBody SysDict record) {
- // return HttpResult.ok(sysDictService.save(record));
- Integer result = sysDictService.insertSelective(record);
- return HttpResult.ok(result);
- }
- // @PreAuthorize("hasAuthority('sys:dict:edit')")
- @PostMapping(value = "/edit")
- public HttpResult edit(@RequestBody SysDict record) {
- // return HttpResult.ok(sysDictService.save(record));
- Integer result = sysDictService.updateSelective(record);
- return HttpResult.ok(result);
- }
- // @PreAuthorize("hasAuthority('sys:dict:add') AND hasAuthority('sys:dict:edit')")
- @PostMapping(value = "/savetype")
- public HttpResult savetype(@RequestBody SysDictType record) {
- return HttpResult.ok(sysDictTypeService.insertSelective(record));
- }
- // @PreAuthorize("hasAuthority('sys:dict:delete')")
- @PostMapping(value = "/delete")
- public HttpResult delete(@RequestBody List<SysDict> records) {
- return HttpResult.ok(sysDictService.delete(records));
- }
- // @PreAuthorize("hasAuthority('sys:dict:view')")
- @PostMapping(value = "/findPage")
- public HttpResult findPage(@RequestBody PageRequest pageRequest) {
- return HttpResult.ok(sysDictService.findPage(pageRequest));
- }
- // // @PreAuthorize("hasAuthority('sys:dict:view')")
- @GetMapping(value = "/findByLable")
- public HttpResult findByLable(@RequestParam String lable, HttpServletRequest request) {
- List<SysDict> byLable = sysDictService.findByLable(lable);
- if (byLable == null || byLable.size() == 0) {
- // 获取用户名
- String deptId = JwtTokenUtils.getDeptIdFromRequest(request);
- lable = lable.toLowerCase();
- switch (lable) {
- case "inscompanycmain":
- List<EsmInsCompany> lst = esmInsCompanyService.list();
- /*// 查询当前登录的用户对应的角色是不是管理员,是管理员的话显示全部供应商,否则显示当前用户对于的供应商
- if (!StringUtils.isNullOrEmpty(deptId)){
- if (SysConstants.DEPT.equals(deptId)){
- lst = esmInsCompanyService.selectAll();
- }else{
- deptId=deptId.substring(0,3);
- lst = esmInsCompanyService.selectList(" where parent_id like ? and (parent_id='0' or LENGTH(t.parent_id)=3) ",new Object[]{deptId+"%"});
- }
- }*/
- byLable = new TreeList<>();
- for (EsmInsCompany esmInsCompany : lst) {
- SysDict sysDict = new SysDict();
- sysDict.setValue(esmInsCompany.getId());
- sysDict.setLabel(esmInsCompany.getName());
- byLable.add(sysDict);
- }
- break;
- case "comcode":
- case "ydcomcode": // 下拉框,要改成层级的那样
- List<TreeSysDeptVO> treeSysDeptVOList = null;
- /*if (SysConstants.DEPT.equals(deptId)){
- deptId="";
- }else{
- if (deptId.contains("D")){
- deptId = deptId.substring(0,deptId.indexOf("D"));
- }
- if (3 == deptId.length()){ // 商户管理员
- deptId = deptId;
- }else{ // 其他分支机构负责人
- deptId = deptId.substring(0,5);
- }
- }*/
- deptId = "";
- treeSysDeptVOList = sysDeptService.selectListWhere("and id like ? order by id ", new Object[]{deptId + "%"});
- for (TreeSysDeptVO treeSysDeptVO : treeSysDeptVOList) {
- if ("0".equals(treeSysDeptVO.getParentId())) {
- SysDict sysDict = new SysDict();
- sysDict.setValue(treeSysDeptVO.getId());
- sysDict.setLabel(treeSysDeptVO.getName());
- sysDict.setDeptId(treeSysDeptVO.getId());
- sysDict.setDeptParentId(treeSysDeptVO.getParentId());
- sysDict.setDeptLevel(treeSysDeptVO.getComlevel());
- byLable.add(sysDict);
- }
- }
- getTree(byLable, treeSysDeptVOList);
- break;
- case "comcode1and2":
- List<TreeSysDeptVO> comcode1and2List = null;
- /*if (SysConstants.DEPT.equals(deptId)){
- deptId="";
- }else{
- if (deptId.length()!=3 && deptId.contains("D")){
- deptId=deptId.substring(0,deptId.indexOf("D"));
- }else{
- deptId = deptId.substring(0,3);
- }
- }*/
- deptId = "";
- comcode1and2List = sysDeptService.selectListWhere("and (id like ? or id = ? )and comlevel in('0','2') order by id ", new Object[]{deptId + "%", StringUtils.isNullOrEmpty(deptId) ? deptId : deptId.substring(0, 3)});
- for (TreeSysDeptVO treeSysDeptVO : comcode1and2List) {
- // 设置第一级
- if ("0".equals(treeSysDeptVO.getComlevel())) {
- SysDict sysDict = new SysDict();
- sysDict.setValue(treeSysDeptVO.getId());
- sysDict.setLabel(treeSysDeptVO.getName());
- sysDict.setDeptId(treeSysDeptVO.getId());
- sysDict.setDeptParentId(treeSysDeptVO.getParentId());
- sysDict.setDeptLevel(treeSysDeptVO.getComlevel());
- byLable.add(sysDict);
- }
- }
- for (TreeSysDeptVO treeSysDeptVO : comcode1and2List) {
- if ("2".equals(treeSysDeptVO.getComlevel())) {
- for (SysDict dict : byLable) {
- // 设置第二级
- if (dict.getDeptId().equals(treeSysDeptVO.getParentId())) {
- SysDict sysDict = new SysDict();
- sysDict.setValue(treeSysDeptVO.getId());
- sysDict.setLabel(treeSysDeptVO.getName());
- sysDict.setDeptId(treeSysDeptVO.getId());
- sysDict.setDeptParentId(treeSysDeptVO.getParentId());
- sysDict.setDeptLevel(treeSysDeptVO.getComlevel());
- dict.getChildren().add(sysDict);
- }
- }
- }
- }
- break;
- case "classcode":
- StringBuffer whereStr = new StringBuffer(" where 1=1 and del_flag=0"); //不含已删除
- ArrayList<String> params = new ArrayList<String>();
- whereStr.append(" and parent_id=?");
- params.add("0");
- List<EsmProduct> esmProducts = esmProductService.selectList(whereStr.toString(), params.toArray());
- byLable = new TreeList<>();
- for (EsmProduct product : esmProducts) {
- SysDict sysDict = new SysDict();
- sysDict.setValue(product.getId());
- sysDict.setLabel(product.getName());
- byLable.add(sysDict);
- }
- break;
- case "account":
- deptId = deptId.substring(0, 3);
- List<SysAccount> list = sysAccountService.findByDeptId(deptId);
- byLable = new TreeList<>();
- for (SysAccount sysAccount : list) {
- SysDict sysDict = new SysDict();
- sysDict.setValue(sysAccount.getId());
- sysDict.setLabel(sysAccount.getName());
- byLable.add(sysDict);
- }
- break;
- default:
- break;
- }
- }
- return HttpResult.ok(byLable);
- }
- private void getTree(List<SysDict> byLable, List<TreeSysDeptVO> treeSysDeptVOList) {
- if (!CollectionUtils.isEmpty(byLable)) {
- for (SysDict sysDict : byLable) {
- for (TreeSysDeptVO treeSysDeptVO : treeSysDeptVOList) {
- if (treeSysDeptVO.getParentId().equals(sysDict.getValue())) { // 第二层
- SysDict sysDict1 = new SysDict();
- sysDict1.setValue(treeSysDeptVO.getId());
- sysDict1.setLabel(treeSysDeptVO.getName());
- sysDict1.setDeptId(treeSysDeptVO.getId());
- sysDict1.setDeptParentId(treeSysDeptVO.getParentId());
- sysDict1.setDeptLevel(treeSysDeptVO.getComlevel());
- sysDict.getChildren().add(sysDict1);
- }
- }
- getTree(sysDict.getChildren(), treeSysDeptVOList);
- }
- }
- }
- @GetMapping(value = "/findMyDictTypeTree")
- public HttpResult findMyDictTypeTree() {
- SysUser sysUser = getUser();
- return HttpResult.ok(sysDictTypeService.selectAll());
- }
- @GetMapping(value = "/findLeftDictTree")
- public HttpResult findLeftDictTree(String deptCode) {
- //return HttpResult.ok(sysDictTypeServicexx.selectListTreeSysDictVO(deptCode));
- List<SysDictType> lst = sysDictTypeService.selectAll();
- return HttpResult.ok(lst);
- }
- /**
- * 枚举类字典
- *
- * @author: lig
- * @date: 2023年04月10日 0010
- */
- @ApiOperation(value = "根据多个字典类型查询字典数据")
- @GetMapping("/listAllDataByTypes")
- public List<DictionaryManagement> listAllDataByTypes(@RequestParam Set<String> dictTypeList) {
- List<DictionaryManagement> dmList = new ArrayList<>();
- Map<String, DictionaryManagement> dmMap = DictEnumConfig.getDmMap();
- Set<String> dictTypeListRemain = new HashSet<>();
- for (String dictType : dictTypeList) {
- if (dmMap.containsKey(dictType)) {
- DictionaryManagement dictionaryManagement = dmMap.get(dictType);
- dmList.add(dictionaryManagement);
- } else {
- dictTypeListRemain.add(dictType);
- }
- }
- // List<DictionaryManagement> dictionaryManagements = dictionaryManagementService.listAllDataByTypes(dictTypeListRemain);
- // dmList.addAll(dictionaryManagements);
- return dmList;
- }
- /**
- * 枚举类
- *
- * @author: lig
- * @date: 2023年04月10日 0010
- */
- @ApiOperation(value = "获取字典列表")
- @GetMapping("/dictList")
- public List<DictionaryManagement> dictTypeList(String type) {
- List<DictionaryManagement> dictList = DictEnumConfig.dictManageList;
- if (StringUtils.isNotEmpty(type)) {
- List<DictionaryManagement> result = new ArrayList<>();
- dictList.stream().forEach(a -> {
- if (a.getDictType().equals(type)) {
- result.add(a);
- }
- });
- return result;
- }
- return dictList;
- }
- }
|