新增区域模块除controller

This commit is contained in:
clunt 2022-03-17 14:54:40 +08:00
parent e2ac70f656
commit ac35ae92e2
5 changed files with 345 additions and 0 deletions

View File

@ -0,0 +1,52 @@
package com.ghy.system.domain;
import com.ghy.common.annotation.Excel;
import com.ghy.common.core.domain.BaseEntity;
import lombok.Data;
/**
* @author clunt
* 区域表
*/
@Data
public class SysArea extends BaseEntity {
private static final long serialVersionUID = 1L;
@Excel(name = "主键id", cellType = Excel.ColumnType.NUMERIC)
private Long areaId;
@Excel(name = "区域编码", cellType = Excel.ColumnType.STRING)
private String areaCode;
@Excel(name = "区域名称", cellType = Excel.ColumnType.STRING)
private String areaName;
@Excel(name = "父级区域编码", cellType = Excel.ColumnType.STRING)
private String parentCode;
@Excel(name = "合并名称 如. 北京,西城区", cellType = Excel.ColumnType.STRING)
private String mergerName;
@Excel(name = "短名称", cellType = Excel.ColumnType.STRING)
private String shortName;
@Excel(name = "合并短名称 如 北京,西城", cellType = Excel.ColumnType.STRING)
private String mergerShortName;
@Excel(name = "级别 1.省 2.市 3.区 4.街道", cellType = Excel.ColumnType.STRING)
private Integer levelType;
@Excel(name = "拼音", cellType = Excel.ColumnType.STRING)
private String pinyin;
@Excel(name = "首字母", cellType = Excel.ColumnType.STRING)
private String firstChar;
@Excel(name = "经度", cellType = Excel.ColumnType.STRING)
private String lng;
@Excel(name = "纬度", cellType = Excel.ColumnType.STRING)
private String lat;
}

View File

@ -0,0 +1,49 @@
package com.ghy.system.mapper;
import com.ghy.system.domain.SysArea;
import java.util.List;
/**
* @author clunt
* 区域表Mapper层
*/
public interface SysAreaMapper {
/**
* @param sysArea 筛选条件
* @return 返回结果
*/
public List<SysArea> selectSysAreaList(SysArea sysArea);
/**
* @param areaId 区域id
* @return 区域实体
*/
public SysArea selectById(Long areaId);
/**
* @param areaCode 区域编码
* @return 区域实体
*/
public SysArea selectByAreaCode(String areaCode);
/**
* @param areaId id数组
* @return 删除成功条数
*/
public int deleteSysAreaByIds(Long [] areaId);
/**
* @param sysArea 更新内容
* @return 成功条数
*/
public int updateSysArea(SysArea sysArea);
/**
* @param sysArea 新增区域实体
* @return 成功条数
*/
public int insertSysArea(SysArea sysArea);
}

View File

@ -0,0 +1,49 @@
package com.ghy.system.service;
import com.ghy.system.domain.SysArea;
import java.util.List;
/**
* @author clunt
* 区域表Service层
*/
public interface ISysAreaService {
/**
* @param sysArea 筛选条件
* @return 返回结果
*/
public List<SysArea> selectSysAreaList(SysArea sysArea);
/**
* @param areaId 区域id
* @return 区域实体
*/
public SysArea selectById(Long areaId);
/**
* @param areaCode 区域编码
* @return 区域实体
*/
public SysArea selectByAreaCode(String areaCode);
/**
* @param ids id数组
* @return 删除成功条数
*/
public int deleteSysAreaByIds(String ids);
/**
* @param sysArea 更新内容
* @return 成功条数
*/
public int updateSysArea(SysArea sysArea);
/**
* @param sysArea 新增区域实体
* @return 成功条数
*/
public int insertSysArea(SysArea sysArea);
}

View File

@ -0,0 +1,68 @@
package com.ghy.system.service.impl;
import com.ghy.common.core.text.Convert;
import com.ghy.common.exception.ServiceException;
import com.ghy.system.domain.SysArea;
import com.ghy.system.mapper.SysAreaMapper;
import com.ghy.system.service.ISysAreaService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
/**
* @author clunt
* 区域表Impl层
*/
@Service
public class SysAreaServiceImpl implements ISysAreaService {
@Resource
private SysAreaMapper sysAreaMapper;
@Override
public List<SysArea> selectSysAreaList(SysArea sysArea) {
return sysAreaMapper.selectSysAreaList(sysArea);
}
@Override
public SysArea selectById(Long areaId) {
return sysAreaMapper.selectById(areaId);
}
@Override
public SysArea selectByAreaCode(String areaCode) {
return sysAreaMapper.selectByAreaCode(areaCode);
}
@Override
public int deleteSysAreaByIds(String ids) {
Long[] areaIds = Convert.toLongArray(ids);
for (Long areaId : areaIds)
{
SysArea sysArea = selectById(areaId);
if (countUseSysAreaById(sysArea) > 0)
{
throw new ServiceException(String.format("%1$s正在使用,不能删除", sysArea.getAreaName()));
}
}
return sysAreaMapper.deleteSysAreaByIds(areaIds);
}
@Override
public int updateSysArea(SysArea sysArea) {
return sysAreaMapper.updateSysArea(sysArea);
}
@Override
public int insertSysArea(SysArea sysArea) {
return sysAreaMapper.insertSysArea(sysArea);
}
public int countUseSysAreaById(SysArea sysArea){
//TODO 校验区域是否使用
return 0;
}
}

View File

@ -0,0 +1,127 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ghy.system.mapper.SysAreaMapper">
<resultMap id="SysAreaResult" type="com.ghy.system.domain.SysArea">
<result property="areaId" column="area_id" />
<result property="areaCode" column="area_code" />
<result property="areaName" column="area_name" />
<result property="parentCode" column="parent_code" />
<result property="mergerName" column="merger_name" />
<result property="shortName" column="short_name" />
<result property="mergerShortName" column="merger_short_name" />
<result property="levelType" column="level_type" />
<result property="pinyin" column="pinyin" />
<result property="firstChar" column="first_char" />
<result property="lng" column="lng" />
<result property="lat" column="lat" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
</resultMap>
<sql id="selectSysArea">
SELECT area_id, area_code, area_name, parent_code, merger_name, short_name, merger_short_name,
level_type, pinyin, first_char, lng, lat, create_by, create_time, remark
FROM sys_area
</sql>
<select id="selectSysAreaList" parameterType="com.ghy.system.domain.SysArea" resultMap="SysAreaResult">
<include refid="selectSysArea" />
<where>
<if test="areaCode != null and areaCode != ''">
AND area_code like concat('%', #{goodsCode}, '%')
</if>
<if test="areaName != null and areaName != ''">
AND area_name like concat('%', #{areaName}, '%')
</if>
</where>
</select>
<select id="selectById" parameterType="long" resultMap="SysAreaResult">
<include refid="selectSysArea"/>
<where>
<if test="areaId != null and areaId != 0">
AND area_id = #{areaId}
</if>
</where>
</select>
<select id="selectByAreaCode" parameterType="string" resultMap="SysAreaResult">
<include refid="selectSysArea"/>
<where>
<if test="areaCode != null and areaCode != ''">
AND area_code = #{areaCode}
</if>
</where>
</select>
<delete id="deleteSysAreaByIds" parameterType="Long">
delete from sys_area where area_id in
<foreach collection="array" item="areaId" open="(" separator="," close=")">
#{areaId}
</foreach>
</delete>
<update id="updateSysArea" parameterType="com.ghy.system.domain.SysArea">
update sys_area
<set>
<if test="areaCode != null and areaCode != ''">area_code = #{areaCode},</if>
<if test="areaName != null and areaName != ''">area_name = #{areaName},</if>
<if test="parentCode != null and parentCode != ''">parent_code = #{parentCode},</if>
<if test="mergerName != null and mergerName != ''">merger_name = #{mergerName},</if>
<if test="shortName != null and shortName != ''">short_name = #{shortName},</if>
<if test="mergerShortName != null and mergerShortName != ''">merger_short_name = #{mergerShortName},</if>
<if test="levelType != null and levelType != ''">level_type = #{levelType},</if>
<if test="pinyin != null and pinyin != ''">pinyin = #{pinyin},</if>
<if test="firstChar != null and firstChar != ''">first_char = #{firstChar},</if>
<if test="lng != null and lng != ''">lng = #{lng},</if>
<if test="lat != null and lat != ''">lat = #{lat},</if>
<if test="remark != null">remark = #{remark},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
update_time = sysdate()
</set>
where goods_id = #{goodsId}
</update>
<insert id="insertSysArea" parameterType="com.ghy.system.domain.SysArea" useGeneratedKeys="true" keyProperty="areaId">
insert into sys_area(
<if test="areaId != null and areaId != 0">area_id,</if>
<if test="areaCode != null and areaCode != ''">area_code,</if>
<if test="areaName != null and areaName != ''">area_name,</if>
<if test="parentCode != null and parentCode != ''">parent_code,</if>
<if test="mergerName != null and mergerName != ''">merger_name,</if>
<if test="shortName != null and shortName != ''">short_name,</if>
<if test="mergerShortName != null and mergerShortName != ''">merger_short_name,</if>
<if test="levelType != null and levelType != ''">level_type,</if>
<if test="pinyin != null and pinyin != ''">pinyin,</if>
<if test="firstChar != null and firstChar != ''">first_char,</if>
<if test="lng != null and lng != ''">lng,</if>
<if test="lat != null and lat != ''">lat,</if>
<if test="remark != null and remark != ''">remark,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)values(
<if test="areaId != null and areaId != 0">#{areaId},</if>
<if test="areaCode != null and areaCode != ''">#{areaCode},</if>
<if test="areaName != null and areaName != ''">#{areaName},</if>
<if test="parentCode != null and parentCode != ''">#{parentCode},</if>
<if test="mergerName != null and mergerName != ''">#{mergerName},</if>
<if test="shortName != null and shortName != ''">#{shortName},</if>
<if test="mergerShortName != null and mergerShortName != ''">#{mergerShortName},</if>
<if test="levelType != null and levelType != ''">#{levelType},</if>
<if test="pinyin != null and pinyin != ''">#{pinyin},</if>
<if test="firstChar != null and firstChar != ''">#{firstChar},</if>
<if test="lng != null and lng != ''">#{lng},</if>
<if test="lat != null and lat != ''">#{lat},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
)
</insert>
</mapper>