diff --git a/bonus-api/bonus-api-system/src/main/java/com/bonus/base/api/domain/MaType.java b/bonus-api/bonus-api-system/src/main/java/com/bonus/base/api/domain/MaType.java index 4f2dcef..f99603b 100644 --- a/bonus-api/bonus-api-system/src/main/java/com/bonus/base/api/domain/MaType.java +++ b/bonus-api/bonus-api-system/src/main/java/com/bonus/base/api/domain/MaType.java @@ -1,5 +1,6 @@ package com.bonus.base.api.domain; +import com.bonus.common.core.web.domain.BaseEntity; import com.fasterxml.jackson.annotation.JsonInclude; import lombok.AllArgsConstructor; import lombok.Data; @@ -18,7 +19,7 @@ import java.util.List; @Data @AllArgsConstructor @NoArgsConstructor -public class MaType implements Serializable { +public class MaType extends BaseEntity implements Serializable { private static final long serialVersionUID = 135108051525707131L; /** * id @@ -32,6 +33,17 @@ public class MaType implements Serializable { * 名称 */ private String name; + + /** + * 父级名称 + */ + private String parentName; + + /** + * 编码 + */ + private String code; + /** * 层级 */ diff --git a/bonus-api/bonus-api-system/src/main/java/com/bonus/base/api/domain/TreeSelect.java b/bonus-api/bonus-api-system/src/main/java/com/bonus/base/api/domain/TreeSelect.java index 92dc8d6..af660ad 100644 --- a/bonus-api/bonus-api-system/src/main/java/com/bonus/base/api/domain/TreeSelect.java +++ b/bonus-api/bonus-api-system/src/main/java/com/bonus/base/api/domain/TreeSelect.java @@ -23,6 +23,11 @@ public class TreeSelect implements Serializable private Integer level; + /** + * 编码 + */ + private String code; + private Integer parentId; private String companyId; @@ -34,6 +39,7 @@ public class TreeSelect implements Serializable public TreeSelect(MaType maType) { this.parentId = maType.getParentId(); + this.code = maType.getCode(); this.level = Integer.valueOf(maType.getLevel()); this.id = maType.getId(); this.label = maType.getName(); @@ -50,6 +56,14 @@ public class TreeSelect implements Serializable this.parentId = parentId; } + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + public Integer getId() { diff --git a/bonus-common/bonus-common-core/src/main/java/com/bonus/common/core/web/domain/BaseEntity.java b/bonus-common/bonus-common-core/src/main/java/com/bonus/common/core/web/domain/BaseEntity.java index a9ab2e2..680b3c2 100644 --- a/bonus-common/bonus-common-core/src/main/java/com/bonus/common/core/web/domain/BaseEntity.java +++ b/bonus-common/bonus-common-core/src/main/java/com/bonus/common/core/web/domain/BaseEntity.java @@ -45,6 +45,8 @@ public class BaseEntity implements Serializable /** 创建人 */ private String creator; + private String keyWord; + /** 请求参数 */ @JsonInclude(JsonInclude.Include.NON_EMPTY) private Map params; @@ -113,6 +115,14 @@ public class BaseEntity implements Serializable this.creator = creator; } + public String getKeyWord() { + return keyWord; + } + + public void setKeyWord(String keyWord) { + this.keyWord = keyWord; + } + public Map getParams() { diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/controller/MaTypeController.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/controller/MaTypeController.java index f171de7..fab988f 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/controller/MaTypeController.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/controller/MaTypeController.java @@ -2,17 +2,18 @@ package com.bonus.material.controller; import com.bonus.base.api.domain.MaType; import com.bonus.base.api.domain.TreeSelect; +import com.bonus.common.core.utils.poi.ExcelUtil; import com.bonus.common.core.web.controller.BaseController; import com.bonus.common.core.web.domain.AjaxResult; +import com.bonus.common.security.annotation.RequiresPermissions; import com.bonus.material.service.MaTypeService; +import com.bonus.material.vo.MaTypeVo; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageRequest; -import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; import java.util.List; /** @@ -34,16 +35,49 @@ public class MaTypeController extends BaseController { /** * 根据类型名称查询类型树 * - * @param typeName 类型名称 * @return 查询结果 */ @ApiOperation(value = "根据类型名称查询类型树") + @RequiresPermissions("material:maType:query") @GetMapping("/getMaTypeList") - public AjaxResult queryByPage(@RequestParam(required = false, value = "typeName") String typeName) { - List maTypeList = maTypeService.getMaTypeList(typeName); + public AjaxResult queryByPage() { + List maTypeList = maTypeService.getMaTypeList(); return AjaxResult.success(maTypeList); } + /** + * 根据左列表类型id查询右表格 + * + * @param maType + * @return + */ + @ApiOperation(value = "根据左列表类型id查询右表格") + @RequiresPermissions("material:maType:query") + @GetMapping("/getListByMaType") + public AjaxResult getListByMaType(MaType maType) { + startPage(); + List listByMaType = maTypeService.getListByParentId(maType); + return success(getDataTable(listByMaType)); + } + + /** + * 新增数据返回code + * + * @param id + * @return 新增结果 + */ + @ApiOperation(value = "新增数据返回code") + @GetMapping("/addMaType") + public AjaxResult addMaType(@RequestParam(value = "id") Integer id) { + MaType maType ; + if (id == 0) { + return success(maTypeService.getNextChildCode(null)); + } else { + maType = maTypeService.findById(id); + return success(maTypeService.getNextChildCode(maType)); + } + } + /** * 新增数据 * @@ -51,6 +85,7 @@ public class MaTypeController extends BaseController { * @return 新增结果 */ @ApiOperation(value = "新增数据") + @RequiresPermissions("material:maType:add") @PostMapping("/add") public AjaxResult add(@RequestBody MaType maType) { return maTypeService.insert(maType); @@ -63,10 +98,36 @@ public class MaTypeController extends BaseController { * @return 编辑结果 */ @ApiOperation(value = "编辑数据") + @RequiresPermissions("material:maType:edit") @PostMapping("/update") public AjaxResult edit(@RequestBody MaType maType) { return maTypeService.update(maType); } + /** + * 逻辑删除 + * + * @param id 主键 + * @return 删除是否成功 + */ + @DeleteMapping("/{id}") + @RequiresPermissions("material:maType:remove") + public AjaxResult deleteById(@PathVariable("id") Integer id) { + return maTypeService.deleteById(id); + } + + /** + * 导出物资类型列表 + */ + @ApiOperation(value = "导出物资类型列表") + @RequiresPermissions("material:maType:export") + @PostMapping("/export") + public void export(HttpServletResponse response, MaType maType) + { + List list = maTypeService.getListByParentId(maType); + ExcelUtil util = new ExcelUtil<>(MaTypeVo.class); + util.exportExcel(response, list, "物资类型数据"); + } + } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/mapper/MaTypeMapper.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/mapper/MaTypeMapper.java index 1750043..69ad4b2 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/mapper/MaTypeMapper.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/mapper/MaTypeMapper.java @@ -1,6 +1,7 @@ package com.bonus.material.mapper; import com.bonus.base.api.domain.MaType; +import com.bonus.material.vo.MaTypeVo; import org.apache.ibatis.annotations.Param; import org.springframework.data.domain.Pageable; import java.util.List; @@ -13,23 +14,6 @@ import java.util.List; */ public interface MaTypeMapper { - /** - * 查询指定行数据 - * - * @param maType 查询条件 - * @param pageable 分页对象 - * @return 对象列表 - */ - List queryAllByLimit(MaType maType, @Param("pageable") Pageable pageable); - - /** - * 统计总行数 - * - * @param maType 查询条件 - * @return 总行数 - */ - long count(MaType maType); - /** * 新增数据 * @@ -72,9 +56,49 @@ public interface MaTypeMapper { /** * 根据名称查询 - * @param typeName * @return */ - List selectMaTypeTree(String typeName); + List selectMaTypeTree(); + + /** + * 根据父级id查询 + * @param maType + * @return + */ + List getListByParentId(MaType maType); + + /** + * 查询最大code + * @return + */ + String selectCode(); + + /** + * 根据父级id查询 + * @param maType + * @return + */ + MaType getNextChildCode(MaType maType); + + /** + * 根据id查询 + * @param id + * @return + */ + MaType findById(Integer id); + + /** + * 根据id查询 + * @param id + * @return + */ + List selectById(Integer id); + + /** + * 根据id删除 + * @param id + * @return + */ + int deleteById(Integer id); } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/service/MaTypeService.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/service/MaTypeService.java index dc02ee3..c385bb6 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/service/MaTypeService.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/service/MaTypeService.java @@ -3,6 +3,7 @@ package com.bonus.material.service; import com.bonus.base.api.domain.MaType; import com.bonus.base.api.domain.TreeSelect; import com.bonus.common.core.web.domain.AjaxResult; +import com.bonus.material.vo.MaTypeVo; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; @@ -16,15 +17,6 @@ import java.util.List; */ public interface MaTypeService { - /** - * 分页查询 - * - * @param maType 筛选条件 - * @param pageRequest 分页对象 - * @return 查询结果 - */ - Page queryByPage(MaType maType, PageRequest pageRequest); - /** * 新增数据 * @@ -43,8 +35,35 @@ public interface MaTypeService { /** * 根据类型名称查询类型树 - * @param typeName * @return */ - List getMaTypeList(String typeName); + List getMaTypeList(); + + /** + * 根据左列表类型id查询右表格 + * @param maType + * @return + */ + List getListByParentId(MaType maType); + + /** + * 根据id查询code + * @param maType + * @return + */ + MaTypeVo getNextChildCode(MaType maType); + + /** + * 根据id查询 + * @param id + * @return + */ + MaType findById(Integer id); + + /** + * 根据id删除 + * @param id + * @return + */ + AjaxResult deleteById(Integer id); } diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/service/impl/MaTypeServiceImpl.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/service/impl/MaTypeServiceImpl.java index c95ec31..d1036a9 100644 --- a/bonus-modules/bonus-material/src/main/java/com/bonus/material/service/impl/MaTypeServiceImpl.java +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/service/impl/MaTypeServiceImpl.java @@ -6,6 +6,8 @@ import com.bonus.common.core.utils.StringUtils; import com.bonus.common.core.web.domain.AjaxResult; import com.bonus.material.mapper.MaTypeMapper; import com.bonus.material.service.MaTypeService; +import com.bonus.material.vo.MaTypeVo; +import org.apache.commons.collections4.CollectionUtils; import org.springframework.stereotype.Service; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; @@ -28,19 +30,6 @@ public class MaTypeServiceImpl implements MaTypeService { @Resource private MaTypeMapper maTypeDao; - /** - * 分页查询 - * - * @param maType 筛选条件 - * @param pageRequest 分页对象 - * @return 查询结果 - */ - @Override - public Page queryByPage(MaType maType, PageRequest pageRequest) { - long total = this.maTypeDao.count(maType); - return new PageImpl<>(this.maTypeDao.queryAllByLimit(maType, pageRequest), pageRequest, total); - } - /** * 新增数据 * @@ -51,9 +40,10 @@ public class MaTypeServiceImpl implements MaTypeService { public AjaxResult insert(MaType maType) { //根据类型名称判断,去重 MaType type = maTypeDao.queryByName(maType.getName()); - if (type!=null){ - return AjaxResult.error("类型名称重复"); + if (type != null && maType.getId().equals(type.getParentId())) { + return AjaxResult.error("同级下类型名称存在重复!"); } + maType.setLevel(String.valueOf(Integer.parseInt(maType.getLevel()) + 1)); int result = maTypeDao.insert(maType); if (result > 0) { return AjaxResult.success("添加成功"); @@ -83,17 +73,126 @@ public class MaTypeServiceImpl implements MaTypeService { /** * 根据类型名称查询类型树 - * @param typeName * @return */ @Override - public List getMaTypeList(String typeName) { - List maTypes = maTypeDao.selectMaTypeTree(typeName); + public List getMaTypeList() { + List maTypes = maTypeDao.selectMaTypeTree(); List treeSelectList = buildDeptTreeSelect(maTypes); //如果没有查询到那么返回空 return treeSelectList; } + /** + * 根据左列表类型id查询右表格 + * @param maType + * @return + */ + @Override + public List getListByParentId(MaType maType) { + return maTypeDao.getListByParentId(maType); + } + + /** + * 根据id查询code + * @param maType + * @return + */ + @Override + public MaTypeVo getNextChildCode(MaType maType) { + String code = ""; + String c = ""; + String str = ""; + try { + if (maType != null) { + code = maType.getCode(); + c = maType.getCode(); + int len = code.length(); + if (len == 2) { + code += "__"; + } else if (len == 4 || len == 7) { + code += "___"; + } + maType.setCode(code); + maType = maTypeDao.getNextChildCode(maType); + } else { + maType = new MaType(); + maType.setCode("__"); + maType = maTypeDao.getNextChildCode(maType); + } + if (maType == null) { + if (c.length() == 0 || c.length() == 2) { + code = c + "01"; + } else { + code = c + "001"; + } + } else { + code = maType.getCode(); + if (code.length() == 2) { + code = Integer.parseInt(code) + 1 + ""; + if (code.length() == 1) { + code = "0" + code; + } + } else if (code.length() == 4) { + str = code.substring(2, 4); + str = Integer.parseInt(str) + 1 + ""; + if (str.length() == 1) { + str = "0" + str; + } + code = code.substring(0, 2) + str; + } else if (code.length() == 7) { + + str = code.substring(4, 7); + str = Integer.parseInt(str) + 1 + ""; + if (str.length() == 1) { + str = "00" + str; + } else if (str.length() == 2) { + str = "0" + str; + } + code = code.substring(0, 4) + str; + } else if (code.length() == 10) { + str = code.substring(7, 10); + str = Integer.parseInt(str) + 1 + ""; + if (str.length() == 1) { + str = "00" + str; + } else if (str.length() == 2) { + str = "0" + str; + } + code = code.substring(0, 7) + str; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + MaTypeVo maTypeVo = new MaTypeVo(); + maTypeVo.setCode(code); + return maTypeVo; + } + + @Override + public MaType findById(Integer id) { + return maTypeDao.findById(id); + } + + /** + * 根据id删除 + * @param id + * @return + */ + @Override + public AjaxResult deleteById(Integer id) { + //根据id查询删除类型下属是否有关联,有关联无法删除 + List list = maTypeDao.selectById(id); + if (CollectionUtils.isNotEmpty(list)) { + return AjaxResult.error("该类型下有子类型,无法删除"); + } + int result = maTypeDao.deleteById(id); + if (result > 0) { + return AjaxResult.success("删除成功"); + } + return AjaxResult.error("删除失败"); + } + /** * 构建前端所需要下拉树结构 * diff --git a/bonus-modules/bonus-material/src/main/java/com/bonus/material/vo/MaTypeVo.java b/bonus-modules/bonus-material/src/main/java/com/bonus/material/vo/MaTypeVo.java new file mode 100644 index 0000000..cb14823 --- /dev/null +++ b/bonus-modules/bonus-material/src/main/java/com/bonus/material/vo/MaTypeVo.java @@ -0,0 +1,45 @@ +package com.bonus.material.vo; + +import com.bonus.base.api.domain.MaType; +import com.bonus.common.core.annotation.Excel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 物资类型返回vo + * @Author ma_sh + * @create 2024/8/13 14:43 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class MaTypeVo extends MaType { + + @ApiModelProperty("类型编码") + @Excel(name = "类型编码") + private String code; + + @ApiModelProperty("仓库信息") + private String wareHouse ; + + @ApiModelProperty("施工类型") + @Excel(name = "施工类型") + private String constructionType; + + @ApiModelProperty("物资类型") + @Excel(name = "物资类型") + private String materialType; + + @ApiModelProperty("物资名称") + @Excel(name = "物资名称") + private String materialName; + + @ApiModelProperty("规格型号") + @Excel(name = "规格型号") + private String specificationCode; + + @ApiModelProperty("新增类型编码") + private String newCode; +} diff --git a/bonus-modules/bonus-material/src/main/resources/mapper/MaTypeMapper.xml b/bonus-modules/bonus-material/src/main/resources/mapper/MaTypeMapper.xml index a17c296..65234d2 100644 --- a/bonus-modules/bonus-material/src/main/resources/mapper/MaTypeMapper.xml +++ b/bonus-modules/bonus-material/src/main/resources/mapper/MaTypeMapper.xml @@ -68,127 +68,144 @@ where id = #{id} + + update ma_type set is_active = '0' where id = #{id} + - - select id, parent_id, name, level, storage_num, unit_id, buy_price, lease_price, manage_type, is_active, rate_load, test_load, hold_time, file_url, company_id from ma_type - - - and id = #{id} - - - and parent_id = #{parentId} - - - and name = #{name} - - - and level = #{level} - - - and storage_num = #{storageNum} - - - and unit_id = #{unitId} - - - and buy_price = #{buyPrice} - - - and lease_price = #{leasePrice} - - - and manage_type = #{manageType} - - - and is_active = #{isActive} - - - and rate_load = #{rateLoad} - - - and test_load = #{testLoad} - - - and hold_time = #{holdTime} - - - and file_url = #{fileUrl} - - - and company_id = #{companyId} - - - limit #{pageable.offset}, #{pageable.pageSize} + where name = #{name} and is_active = '1' - - - - select - id, parent_id, name, level, storage_num, unit_id, buy_price, lease_price, manage_type, is_active, rate_load, test_load, hold_time, file_url, company_id + id, code, parent_id, name, level, storage_num, unit_id, buy_price, lease_price, manage_type, is_active, rate_load, test_load, hold_time, file_url, company_id from ma_type - where name = #{name} + where level != '4' and is_active = '1' - + SELECT + t.* + FROM + ( + SELECT + mt.id, + mt.`name` AS specificationCode, + mt.`level`, + mtp.`name` AS materialName, + s.`name` AS materialType, + f.`name` AS constructionType, + mt.`code`, + mt.is_active + FROM + ma_type mt + LEFT JOIN ma_type mtp ON mtp.id = mt.parent_id + LEFT JOIN ma_type s ON s.id = mtp.parent_id + LEFT JOIN ma_type f ON f.id = s.parent_id + WHERE + mt.`LEVEL` = 4 UNION + SELECT + mt.id, + NULL AS `NAME`, + mt.`level`, + mt.`name` AS materialName, + mtp.`name` AS materialType, + s.`name` AS constructionType, + mt.`CODE`, + mt.is_active + FROM + ma_type mt + LEFT JOIN ma_type mtp ON mtp.id = mt.PARENT_ID + LEFT JOIN ma_type s ON s.id = mtp.PARENT_ID + WHERE + mt.`LEVEL` = 3 UNION + SELECT + mt.id AS id, + NULL AS `NAME`, + mt.`level`, + NULL AS materialName, + mt.`NAME` AS materialType, + mtp.`NAME` AS constructionType, + mt.`CODE`, + mt.IS_ACTIVE AS enabled + FROM + ma_type mt + LEFT JOIN ma_type mtp ON mtp.id = mt.PARENT_ID + WHERE + mt.`LEVEL` = 2 UNION + SELECT + mt.id AS id, + NULL AS `NAME`, + mt.`level`, + NULL AS materialName, + NULL AS materialType, + mt.`NAME` AS constructionType, + mt.`CODE`, + mt.IS_ACTIVE AS enabled + FROM + ma_type mt + WHERE + mt.`LEVEL` = 1 + ) t + WHERE + t.IS_ACTIVE = '1' + + and ( + t.specificationCode like CONCAT('%',#{keyWord},'%') or + t.`CODE` like CONCAT('%',#{keyWord},'%') or + t.materialName like CONCAT('%',#{keyWord},'%') or + t.materialType like CONCAT('%',#{keyWord},'%') or + t.constructionType like CONCAT('%',#{keyWord},'%') + ) + + + and t.`CODE` like CONCAT(#{code},'%') + + ORDER BY t.`CODE` + + + + + - insert into ma_type(id, parent_id, name, level, storage_num, unit_id, buy_price, lease_price, manage_type, is_active, rate_load, test_load, hold_time, file_url, company_id) @@ -224,16 +241,16 @@ INSERT INTO ma_type - id, - parent_id, + parent_id, name, + code, level, storage_num, unit_id, buy_price, lease_price, manage_type, - is_active, + is_active, rate_load, test_load, hold_time, @@ -243,8 +260,8 @@ VALUES #{id}, - #{parentId}, #{name}, + #{code}, #{level}, #{storageNum}, #{unitId}, diff --git a/bonus-modules/bonus-system/src/main/java/com/bonus/system/controller/SysProfileController.java b/bonus-modules/bonus-system/src/main/java/com/bonus/system/controller/SysProfileController.java index 16a7e33..6401af9 100644 --- a/bonus-modules/bonus-system/src/main/java/com/bonus/system/controller/SysProfileController.java +++ b/bonus-modules/bonus-system/src/main/java/com/bonus/system/controller/SysProfileController.java @@ -110,7 +110,7 @@ public class SysProfileController extends BaseController String username = SecurityUtils.getUsername(); SysUser user = userService.selectUserByUserName(username); String password = user.getPassword(); - String msg= ValidateUtils.isPwd(oldPassword); + String msg= ValidateUtils.isPwd(newPassword); if (StringUtils.isNotEmpty(msg)) { return error(msg); }