jz.kai 2 лет назад
Родитель
Сommit
e326a4fcfd

+ 21 - 0
common/src/main/java/com/jpsoft/prices/modules/base/dao/DestinationDAO.java

@@ -0,0 +1,21 @@
+package com.jpsoft.prices.modules.base.dao;
+
+import java.util.List;
+import org.springframework.stereotype.Repository;
+
+import java.util.Map;
+import com.jpsoft.prices.modules.common.dto.Sort;
+
+@Repository
+public interface DestinationDAO {
+	int insert(com.jpsoft.prices.modules.base.entity.Destination entity);
+	int update(com.jpsoft.prices.modules.base.entity.Destination entity);
+	int exist(String id);
+	com.jpsoft.prices.modules.base.entity.Destination get(String id);
+	int delete(String id);
+	List<com.jpsoft.prices.modules.base.entity.Destination> list();
+	List<com.jpsoft.prices.modules.base.entity.Destination> search(Map<String,Object> searchParams, List<Sort> sortList);
+	List<com.jpsoft.prices.modules.base.entity.Destination> getListByParentId(String parentId);
+	com.jpsoft.prices.modules.base.entity.Destination getByName(String name);
+	List<com.jpsoft.prices.modules.base.entity.Destination> listByParentId(String parentId);
+}

+ 44 - 0
common/src/main/java/com/jpsoft/prices/modules/base/entity/Destination.java

@@ -0,0 +1,44 @@
+package com.jpsoft.prices.modules.base.entity;
+
+import java.util.Date;
+import java.util.List;
+
+import org.springframework.format.annotation.DateTimeFormat;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModelProperty;
+import io.swagger.annotations.ApiModel;
+import lombok.Data;
+
+/**
+  描述:base_area的实体类
+ */
+@Data
+@ApiModel(value = "base_destination的实体类")
+public class Destination {
+        @ApiModelProperty(value = "编号")
+    private String id;
+        @ApiModelProperty(value = "上级编号")
+    private String parentId;
+    @ApiModelProperty(value = "编码")
+    private String code;
+    private String parentName;
+    private String parentFullName;
+        @ApiModelProperty(value = "区域名称")
+    private String name;
+        @ApiModelProperty(value = "是否删除")
+    private Boolean delFlag;
+        @DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone ="GMT+8")
+	    @ApiModelProperty(value = "创建时间")
+    private Date createTime;
+        @ApiModelProperty(value = "创建人")
+    private String createBy;
+        @DateTimeFormat(pattern="yyyy-MM-dd HH:mm")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm",timezone ="GMT+8")
+	    @ApiModelProperty(value = "更新时间")
+    private Date updateTime;
+        @ApiModelProperty(value = "更新人")
+    private String updateBy;
+
+    private List<Destination> children;
+}

+ 20 - 0
common/src/main/java/com/jpsoft/prices/modules/base/service/DestinationService.java

@@ -0,0 +1,20 @@
+package com.jpsoft.prices.modules.base.service;
+
+import java.util.List;
+import java.util.Map;
+
+import com.github.pagehelper.Page;
+import com.jpsoft.prices.modules.common.dto.Sort;
+
+public interface DestinationService {
+	com.jpsoft.prices.modules.base.entity.Destination get(String id);
+	boolean exist(String id);
+	int insert(com.jpsoft.prices.modules.base.entity.Destination model);
+	int update(com.jpsoft.prices.modules.base.entity.Destination model);
+	int delete(String id);
+	List<com.jpsoft.prices.modules.base.entity.Destination> list();
+	Page<com.jpsoft.prices.modules.base.entity.Destination> pageSearch(Map<String, Object> searchParams, int pageNum, int pageSize, boolean count, List<Sort> sortList);
+	List<com.jpsoft.prices.modules.base.entity.Destination> getListByParentId(String parentId);
+	com.jpsoft.prices.modules.base.entity.Destination getByName(String name);
+	List<com.jpsoft.prices.modules.base.entity.Destination> listByParentId(String parentId);
+}

+ 84 - 0
common/src/main/java/com/jpsoft/prices/modules/base/service/impl/DestinationServiceImpl.java

@@ -0,0 +1,84 @@
+package com.jpsoft.prices.modules.base.service.impl;
+
+import java.util.List;
+import java.util.Map;
+import javax.annotation.Resource;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+import com.github.pagehelper.Page;
+import com.jpsoft.prices.modules.common.dto.Sort;
+import com.github.pagehelper.PageHelper;
+
+@Transactional
+@Component(value="destinationService")
+public class DestinationServiceImpl implements com.jpsoft.prices.modules.base.service.DestinationService {
+	@Resource(name="destinationDAO")
+	private com.jpsoft.prices.modules.base.dao.DestinationDAO destinationDAO;
+
+	@Override
+	public com.jpsoft.prices.modules.base.entity.Destination get(String id) {
+		// TODO Auto-generated method stub
+		return destinationDAO.get(id);
+	}
+
+	@Override
+	public int insert(com.jpsoft.prices.modules.base.entity.Destination model) {
+		// TODO Auto-generated method stub
+		//model.setId(UUID.randomUUID().toString());
+		
+		return destinationDAO.insert(model);
+	}
+
+	@Override
+	public int update(com.jpsoft.prices.modules.base.entity.Destination model) {
+		// TODO Auto-generated method stub
+		return destinationDAO.update(model);
+	}
+
+	@Override
+	public int delete(String id) {
+		// TODO Auto-generated method stub
+		return destinationDAO.delete(id);
+	}
+
+	@Override
+	public boolean exist(String id) {
+		// TODO Auto-generated method stub
+		int count = destinationDAO.exist(id);
+		
+		return count > 0 ? true : false;
+	}
+	
+	@Override
+	public List<com.jpsoft.prices.modules.base.entity.Destination> list() {
+		// TODO Auto-generated method stub
+		return destinationDAO.list();
+	}
+		
+	@Override
+	public Page<com.jpsoft.prices.modules.base.entity.Destination> pageSearch(Map<String, Object> searchParams, int pageNumber, int pageSize, boolean count, List<Sort> sortList) {
+        Page<com.jpsoft.prices.modules.base.entity.Destination> page = PageHelper.startPage(pageNumber,pageSize,count).doSelectPage(()->{
+            destinationDAO.search(searchParams,sortList);
+        });
+        
+        return page;
+	}
+
+	@Override
+	public List<com.jpsoft.prices.modules.base.entity.Destination> getListByParentId(String parentId){
+		// TODO Auto-generated method stub
+		return destinationDAO.getListByParentId(parentId);
+	}
+
+	@Override
+	public com.jpsoft.prices.modules.base.entity.Destination getByName(String name) {
+		// TODO Auto-generated method stub
+		return destinationDAO.getByName(name);
+	}
+
+	@Override
+	public List<com.jpsoft.prices.modules.base.entity.Destination> listByParentId(String parentId){
+		// TODO Auto-generated method stub
+		return destinationDAO.listByParentId(parentId);
+	}
+}

+ 119 - 0
common/src/main/resources/mapper/base/Destination.xml

@@ -0,0 +1,119 @@
+<?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">
+<!-- namespace必须指向DAO接口 -->
+<mapper namespace="com.jpsoft.prices.modules.base.dao.DestinationDAO">
+	<resultMap id="DestinationMap" type="com.jpsoft.prices.modules.base.entity.Destination">
+		<id property="id" column="id_" />
+		<result property="parentId" column="parent_id" />
+		<result property="code" column="code_" />
+		<result property="name" column="name_" />
+		<result property="delFlag" column="del_flag" />
+		<result property="createTime" column="create_time" />
+		<result property="createBy" column="create_by" />
+		<result property="updateTime" column="update_time" />
+		<result property="updateBy" column="update_by" />
+	</resultMap>
+	<insert id="insert" parameterType="com.jpsoft.prices.modules.base.entity.Destination">
+	<!--
+	<selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
+		select sys_guid() from dual
+	</selectKey>
+	-->
+	<![CDATA[
+		insert into base_destination
+	    (id_,parent_id,code_,name_,del_flag,create_time,create_by,update_time,update_by)
+		values
+		(
+#{id,jdbcType=VARCHAR}
+,#{parentId,jdbcType=VARCHAR}
+,#{code,jdbcType=VARCHAR}
+,#{name,jdbcType=VARCHAR}
+,#{delFlag,jdbcType= NUMERIC }
+,#{createTime,jdbcType= TIMESTAMP }
+,#{createBy,jdbcType=VARCHAR}
+,#{updateTime,jdbcType= TIMESTAMP }
+,#{updateBy,jdbcType=VARCHAR}
+		)
+	]]>
+	</insert>
+	<delete id="delete" parameterType="string">
+		delete from base_destination where id_=#{id,jdbcType=VARCHAR}
+	</delete>
+	<update id="update" parameterType="com.jpsoft.prices.modules.base.entity.Destination">
+		update base_destination
+		<set>
+				<if test="parentId!=null">
+		parent_id=#{parentId,jdbcType=VARCHAR},
+		</if>
+			<if test="code!=null">
+				code_=#{code,jdbcType=VARCHAR},
+			</if>
+				<if test="name!=null">
+		name_=#{name,jdbcType=VARCHAR},
+		</if>
+				<if test="delFlag!=null">
+		del_flag=#{delFlag,jdbcType= NUMERIC },
+		</if>
+				<if test="createTime!=null">
+		create_time=#{createTime,jdbcType= TIMESTAMP },
+		</if>
+				<if test="createBy!=null">
+		create_by=#{createBy,jdbcType=VARCHAR},
+		</if>
+				<if test="updateTime!=null">
+		update_time=#{updateTime,jdbcType= TIMESTAMP },
+		</if>
+				<if test="updateBy!=null">
+		update_by=#{updateBy,jdbcType=VARCHAR},
+		</if>
+		</set>
+	where id_=#{id}
+	</update>
+	<select id="get" parameterType="string" resultMap="DestinationMap">
+		select 
+id_,parent_id,code_,name_,del_flag,create_time,create_by,update_time,update_by		from base_destination where id_=#{0}
+	</select>
+	<select id="exist" parameterType="string" resultType="int">
+		select count(*) from base_destination where id_=#{0}
+	</select>
+	<select id="list" resultMap="DestinationMap">
+		select * from base_destination
+	</select>
+	<select id="search" parameterType="hashmap" resultMap="DestinationMap">
+		<![CDATA[
+			select * from base_destination
+		]]>
+		<where>
+			del_flag = 0
+			<if test="searchParams.noCode">
+				and code_ NOT LIKE #{searchParams.noCode}
+			</if>
+			<if test="searchParams.name">
+				and name_ LIKE #{searchParams.name}
+			</if>
+			<if test="searchParams.parentId">
+				and parent_id = #{searchParams.parentId}
+			</if>
+		</where>
+		<foreach item="sort" collection="sortList"  open="order by" separator=",">
+	        ${sort.name} ${sort.order}
+	 	</foreach>
+	</select>
+	<select id="getListByParentId" resultMap="DestinationMap">
+		SELECT * FROM base_destination
+		where del_flag = 0
+		and parent_id = #{parentId}
+		ORDER BY create_time ASC
+	</select>
+	<select id="getByName" parameterType="string" resultMap="DestinationMap">
+		select * from base_destination
+		where del_flag=0
+		and name_=#{0}
+		limit 1
+	</select>
+	<select id="listByParentId" resultMap="DestinationMap">
+		SELECT * FROM base_destination
+		where parent_id = #{0}
+	</select>
+</mapper>

+ 304 - 0
web/src/main/java/com/jpsoft/prices/modules/base/controller/DestinationController.java

@@ -0,0 +1,304 @@
+package com.jpsoft.prices.modules.base.controller;
+
+import com.github.pagehelper.Page;
+import com.jpsoft.prices.modules.base.entity.Destination;
+import com.jpsoft.prices.modules.base.service.DestinationService;
+import com.jpsoft.prices.modules.common.dto.MessageResult;
+import com.jpsoft.prices.modules.common.dto.Sort;
+import com.jpsoft.prices.modules.common.utils.PojoUtils;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.*;
+
+@RestController
+@RequestMapping("/base/destination")
+@Api(description = "模版")
+public class DestinationController {
+    private Logger logger = LoggerFactory.getLogger(getClass());
+
+    @Autowired
+    private DestinationService destinationService;
+
+    @ApiOperation(value="创建空记录")
+    @GetMapping("create")
+    public MessageResult<Destination> create(){
+        MessageResult<Destination> msgResult = new MessageResult<>();
+
+        Destination destination = new Destination();
+
+        msgResult.setData(destination);
+        msgResult.setResult(true);
+
+        return msgResult;
+    }
+
+    @ApiOperation(value="添加信息")
+    @PostMapping("add")
+    public MessageResult<Destination> add(@RequestBody Destination destination,@RequestAttribute String subject){
+        MessageResult<Destination> msgResult = new MessageResult<>();
+
+        try {
+            destination.setId(UUID.randomUUID().toString());
+            destination.setDelFlag(false);
+            destination.setCreateBy(subject);
+            destination.setCreateTime(new Date());
+
+            Destination destinationParent = destinationService.get(destination.getParentId());
+            if(destinationParent != null){
+                destination.setCode(destinationParent.getCode() + "," + destination.getId());
+            }
+            else{
+                destination.setCode(destination.getId());
+            }
+
+            int affectCount = destinationService.insert(destination);
+
+            if (affectCount > 0) {
+                msgResult.setResult(true);
+                msgResult.setData(destination);
+            } else {
+                msgResult.setResult(false);
+                msgResult.setMessage("数据库添加失败");
+            }
+        }
+        catch(Exception ex){
+            logger.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
+    @ApiOperation(value="获取信息")
+    @GetMapping("edit/{id}")
+    public MessageResult<Destination> edit(@PathVariable("id") String id){
+        MessageResult<Destination> msgResult = new MessageResult<>();
+
+        try {
+            Destination destination = destinationService.get(id);
+
+            if (destination != null) {
+                msgResult.setResult(true);
+                msgResult.setData(destination);
+            } else {
+                msgResult.setResult(false);
+                msgResult.setMessage("数据库不存在该记录!");
+            }
+        }
+        catch(Exception ex){
+            logger.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
+    @ApiOperation(value="更新用户")
+    @PostMapping("update")
+    public MessageResult<Destination> update(@RequestBody Destination destination,@RequestAttribute String subject){
+        MessageResult<Destination> msgResult = new MessageResult<>();
+
+        try {
+            destination.setUpdateBy(subject);
+            destination.setUpdateTime(new Date());
+
+            Destination destinationParent = destinationService.get(destination.getParentId());
+            if(destinationParent != null){
+                destination.setCode(destinationParent.getCode() + "," + destination.getId());
+            }
+            else{
+                destination.setCode(destination.getId());
+            }
+
+            int affectCount = destinationService.update(destination);
+
+            if (affectCount > 0) {
+                updateChildCode(destination.getId());
+
+                msgResult.setResult(true);
+                msgResult.setData(destination);
+            } else {
+                msgResult.setResult(false);
+                msgResult.setMessage("数据库更新失败");
+            }
+        }
+        catch(Exception ex){
+            logger.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
+    @ApiOperation(value="更新code")
+    @PostMapping("updateChildCode")
+    public void updateChildCode(String parentId){
+        Destination destination = destinationService.get(parentId);
+        List<Destination> childList = destinationService.listByParentId(parentId);
+        for(Destination child : childList){
+            child.setCode(destination.getCode() + "," + child.getId());
+            destinationService.update(child);
+
+            updateChildCode(child.getId());
+        }
+    }
+
+    @ApiOperation(value="删除")
+    @PostMapping("delete/{id}")
+    public MessageResult<Integer> delete(@PathVariable("id") String id,@RequestAttribute String subject){
+        MessageResult<Integer> msgResult = new MessageResult<>();
+
+        try {
+            Destination destination = destinationService.get(id);
+            destination.setDelFlag(true);
+            destination.setUpdateBy(subject);
+            destination.setUpdateTime(new Date());
+
+            int affectCount = destinationService.update(destination);
+
+            if (affectCount > 0) {
+                msgResult.setResult(true);
+                msgResult.setData(affectCount);
+            } else {
+                msgResult.setResult(false);
+                msgResult.setMessage("删除失败");
+            }
+        }
+        catch(Exception ex){
+            logger.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
+
+    @ApiOperation(value="批量删除")
+    @PostMapping("batchDelete")
+    public MessageResult<Integer> batchDelete(@RequestBody List<String> idList,@RequestAttribute String subject){
+        MessageResult<Integer> msgResult = new MessageResult<>();
+
+        try {
+            int affectCount = 0;
+
+            for (String id : idList) {
+                Destination destination = destinationService.get(id);
+                destination.setDelFlag(true);
+                destination.setUpdateBy(subject);
+                destination.setUpdateTime(new Date());
+
+                affectCount += destinationService.update(destination);
+            }
+
+            if (affectCount > 0) {
+                msgResult.setResult(true);
+                msgResult.setData(affectCount);
+            } else {
+                msgResult.setResult(false);
+                msgResult.setMessage("删除失败");
+            }
+        }
+        catch(Exception ex){
+            logger.error(ex.getMessage(),ex);
+
+            msgResult.setResult(false);
+            msgResult.setMessage(ex.getMessage());
+        }
+
+        return msgResult;
+    }
+
+    @ApiOperation(value="列表")
+    @RequestMapping(value = "pageList",method = RequestMethod.POST)
+    public MessageResult<Map> pageList(
+            String parentId, String name,
+            @RequestParam(name="pageIndex",defaultValue = "1") int pageIndex,
+            @RequestParam(name="pageSize",defaultValue = "10") int pageSize,
+            @RequestAttribute String subject){
+        MessageResult<Map> msgResult = new MessageResult<>();
+
+        Map<String,Object> searchParams = new HashMap<>();
+        if(StringUtils.isNotEmpty(parentId) && !"null".equals(parentId)){
+            searchParams.put("parentId", parentId);
+        }
+        if(StringUtils.isNotEmpty(name)){
+            searchParams.put("name", "%" + name + "%");
+        }
+
+        List<Sort> sortList = new ArrayList<>();
+        sortList.add(new Sort("code_","asc"));
+
+        Page<Destination> page = destinationService.pageSearch(searchParams,pageIndex,pageSize,true,sortList);
+        for(Destination li : page.getResult()){
+            li.setParentFullName(getFullName(li.getCode()));
+            if(StringUtils.isNotEmpty(li.getParentId())) {
+                Destination destination = destinationService.get(li.getParentId());
+                li.setParentName(destination.getName());
+            }
+        }
+
+        msgResult.setResult(true);
+        msgResult.setData(PojoUtils.pageWrapper(page));
+
+        return msgResult;
+    }
+
+    private List<Destination> listByParentId(String parentId){
+        List<Destination> list = new ArrayList<>();
+
+        list = destinationService.getListByParentId(parentId);
+        for (Destination destination : list){
+            destination.setChildren(listByParentId(destination.getId()));
+        }
+
+        return list;
+    }
+
+    @ApiOperation(value = "查询")
+    @RequestMapping(value = "query", method = RequestMethod.POST)
+    public MessageResult<List> query(String code) {
+        MessageResult<List> msgResult = new MessageResult<>();
+
+        Map<String, Object> searchParams = new HashMap<>();
+
+        List<Sort> sortList = new ArrayList<>();
+        sortList.add(new Sort("parent_id", "asc"));
+        sortList.add(new Sort("name_", "asc"));
+
+        if (StringUtils.isNotEmpty(code) && !"undefined".equals(code)) {
+            searchParams.put("noCode", code + "%");
+        }
+
+        Page<Destination> page = destinationService.pageSearch(searchParams,1,10000,false,sortList);
+        List<Destination> destinationList = page.getResult();
+        msgResult.setResult(true);
+        msgResult.setData(destinationList);
+
+        return msgResult;
+    }
+
+    private String getFullName(String code){
+        List<String> names = new ArrayList<>();
+        String[] ids = code.split(",");
+        for(String id : ids){
+            Destination destination = destinationService.get(id);
+            names.add(destination.getName());
+        }
+
+        return StringUtils.join(names, " > ");
+    }
+}