类型管理

This commit is contained in:
mashuai 2024-08-14 16:38:46 +08:00
parent 685fd8e14b
commit a5ec76ab8a
10 changed files with 473 additions and 172 deletions

View File

@ -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;
/**
* 层级
*/

View File

@ -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()
{

View File

@ -45,6 +45,8 @@ public class BaseEntity implements Serializable
/** 创建人 */
private String creator;
private String keyWord;
/** 请求参数 */
@JsonInclude(JsonInclude.Include.NON_EMPTY)
private Map<String, Object> 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<String, Object> getParams()
{

View File

@ -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<TreeSelect> maTypeList = maTypeService.getMaTypeList(typeName);
public AjaxResult queryByPage() {
List<TreeSelect> 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<MaTypeVo> 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<MaTypeVo> list = maTypeService.getListByParentId(maType);
ExcelUtil<MaTypeVo> util = new ExcelUtil<>(MaTypeVo.class);
util.exportExcel(response, list, "物资类型数据");
}
}

View File

@ -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<MaType> 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<MaType> selectMaTypeTree(String typeName);
List<MaType> selectMaTypeTree();
/**
* 根据父级id查询
* @param maType
* @return
*/
List<MaTypeVo> 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<MaTypeVo> selectById(Integer id);
/**
* 根据id删除
* @param id
* @return
*/
int deleteById(Integer id);
}

View File

@ -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<MaType> queryByPage(MaType maType, PageRequest pageRequest);
/**
* 新增数据
*
@ -43,8 +35,35 @@ public interface MaTypeService {
/**
* 根据类型名称查询类型树
* @param typeName
* @return
*/
List<TreeSelect> getMaTypeList(String typeName);
List<TreeSelect> getMaTypeList();
/**
* 根据左列表类型id查询右表格
* @param maType
* @return
*/
List<MaTypeVo> 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);
}

View File

@ -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<MaType> 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<TreeSelect> getMaTypeList(String typeName) {
List<MaType> maTypes = maTypeDao.selectMaTypeTree(typeName);
public List<TreeSelect> getMaTypeList() {
List<MaType> maTypes = maTypeDao.selectMaTypeTree();
List<TreeSelect> treeSelectList = buildDeptTreeSelect(maTypes);
//如果没有查询到那么返回空
return treeSelectList;
}
/**
* 根据左列表类型id查询右表格
* @param maType
* @return
*/
@Override
public List<MaTypeVo> 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<MaTypeVo> 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("删除失败");
}
/**
* 构建前端所需要下拉树结构
*

View File

@ -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;
}

View File

@ -68,127 +68,144 @@
where id = #{id}
</set>
</update>
<delete id="deleteById">
update ma_type set is_active = '0' where id = #{id}
</delete>
<!--查询指定行数据-->
<select id="queryAllByLimit" resultMap="MaTypeMap">
<select id="queryByName" resultMap="MaTypeMap">
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
<where>
<if test="id != null">
and id = #{id}
</if>
<if test="parentId != null">
and parent_id = #{parentId}
</if>
<if test="name != null and name != ''">
and name = #{name}
</if>
<if test="level != null and level != ''">
and level = #{level}
</if>
<if test="storageNum != null and storageNum != ''">
and storage_num = #{storageNum}
</if>
<if test="unitId != null and unitId != ''">
and unit_id = #{unitId}
</if>
<if test="buyPrice != null and buyPrice != ''">
and buy_price = #{buyPrice}
</if>
<if test="leasePrice != null and leasePrice != ''">
and lease_price = #{leasePrice}
</if>
<if test="manageType != null and manageType != ''">
and manage_type = #{manageType}
</if>
<if test="isActive != null and isActive != ''">
and is_active = #{isActive}
</if>
<if test="rateLoad != null and rateLoad != ''">
and rate_load = #{rateLoad}
</if>
<if test="testLoad != null and testLoad != ''">
and test_load = #{testLoad}
</if>
<if test="holdTime != null and holdTime != ''">
and hold_time = #{holdTime}
</if>
<if test="fileUrl != null and fileUrl != ''">
and file_url = #{fileUrl}
</if>
<if test="companyId != null and companyId != ''">
and company_id = #{companyId}
</if>
</where>
limit #{pageable.offset}, #{pageable.pageSize}
where name = #{name} and is_active = '1'
</select>
<!--统计总行数-->
<select id="count" resultType="java.lang.Long">
select count(1)
from ma_type
<where>
<if test="id != null">
and id = #{id}
</if>
<if test="parentId != null">
and parent_id = #{parentId}
</if>
<if test="name != null and name != ''">
and name = #{name}
</if>
<if test="level != null and level != ''">
and level = #{level}
</if>
<if test="storageNum != null and storageNum != ''">
and storage_num = #{storageNum}
</if>
<if test="unitId != null and unitId != ''">
and unit_id = #{unitId}
</if>
<if test="buyPrice != null and buyPrice != ''">
and buy_price = #{buyPrice}
</if>
<if test="leasePrice != null and leasePrice != ''">
and lease_price = #{leasePrice}
</if>
<if test="manageType != null and manageType != ''">
and manage_type = #{manageType}
</if>
<if test="isActive != null and isActive != ''">
and is_active = #{isActive}
</if>
<if test="rateLoad != null and rateLoad != ''">
and rate_load = #{rateLoad}
</if>
<if test="testLoad != null and testLoad != ''">
and test_load = #{testLoad}
</if>
<if test="holdTime != null and holdTime != ''">
and hold_time = #{holdTime}
</if>
<if test="fileUrl != null and fileUrl != ''">
and file_url = #{fileUrl}
</if>
<if test="companyId != null and companyId != ''">
and company_id = #{companyId}
</if>
</where>
</select>
<select id="queryByName" resultType="com.bonus.base.api.domain.MaType">
<select id="selectMaTypeTree" resultMap="MaTypeMap" parameterType="java.lang.String">
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>
<select id="selectMaTypeTree" resultType="com.bonus.base.api.domain.MaType">
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
where level != 5 and is_active = '1'
<select id="getListByParentId" resultType="com.bonus.material.vo.MaTypeVo">
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'
<if test="keyWord != null and keyWord != ''">
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},'%')
)
</if>
<if test="code != null and code != ''">
and t.`CODE` like CONCAT(#{code},'%')
</if>
ORDER BY t.`CODE`
</select>
<select id="selectCode" resultType="java.lang.String">
SELECT code
FROM ma_type
WHERE code like '__'
ORDER BY code DESC
LIMIT 1
</select>
<select id="getNextChildCode" resultType="com.bonus.base.api.domain.MaType">
SELECT `code`
FROM ma_type
WHERE `code` like #{code}
ORDER BY `code` DESC
LIMIT 1
</select>
<select id="findById" resultType="com.bonus.base.api.domain.MaType">
SELECT DISTINCT
mt.id AS id,
mt.`code`,
mt.`level`,
mt.storage_num AS storageNum,
mt.hold_time,
mt1.`name` AS parentName,
mt.`name`
FROM
ma_type mt
LEFT JOIN ma_type mt1 ON mt1.id = mt.parent_id
WHERE
mt.is_active = '1' and mt.id = #{id}
</select>
<select id="selectById" resultType="com.bonus.material.vo.MaTypeVo">
SELECT
mt.id,
mt.`code`,
mt.`level`,
mt.storage_num,
mt.hold_time,
mt.`name`
FROM
ma_type mt
WHERE
mt.is_active = '1' and mt.parent_id = #{id}
</select>
<insert id="insertBatch" keyProperty="" useGeneratedKeys="true">
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 id="insert">
INSERT INTO ma_type
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null and id != ''">id,</if>
<if test="parentId != null and parentId != ''">parent_id,</if>
<if test="id != null and id != ''">parent_id,</if>
<if test="name != null and name != ''">name,</if>
<if test="code != null and code != ''">code,</if>
<if test="level != null and level != ''">level,</if>
<if test="storageNum != null and storageNum != ''">storage_num,</if>
<if test="unitId != null and unitId != ''">unit_id,</if>
<if test="buyPrice != null and buyPrice != ''">buy_price,</if>
<if test="leasePrice != null and leasePrice != ''">lease_price,</if>
<if test="manageType != null and manageType != ''">manage_type,</if>
<if test="isActive != null and isActive != ''">is_active,</if>
is_active,
<if test="rateLoad != null and rateLoad != ''">rate_load,</if>
<if test="testLoad != null and testLoad != ''">test_load,</if>
<if test="holdTime != null and holdTime != ''">hold_time,</if>
@ -243,8 +260,8 @@
VALUES
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null and id != ''">#{id},</if>
<if test="parentId != null and parentId != ''">#{parentId},</if>
<if test="name != null and name != ''">#{name},</if>
<if test="code != null and code != ''">#{code},</if>
<if test="level != null and level != ''">#{level},</if>
<if test="storageNum != null and storageNum != ''">#{storageNum},</if>
<if test="unitId != null and unitId != ''">#{unitId},</if>

View File

@ -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);
}