Commit 17356083 by zhangkb

台账目录和台账数据crud接口代码上传

parent c1b8f152
package com.keymobile.indicators.api.parameter;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.keymobile.indicators.constant.Constants;
import com.keymobile.indicators.model.entity.parameter.ParameterCatalog;
import com.keymobile.indicators.model.entity.parameter.ParameterData;
import com.keymobile.indicators.service.parameter.ParameterService;
import com.keymobile.indicators.utils.LogManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@Api(tags={"台账管理功能接口"})
@RestController
@RequestMapping(value = "/parameter")
public class ParameterCtrl {
@Autowired
private ParameterService parameterService;
@ApiOperation(value = "新建台账目录", notes = "新建台账目录")
@PostMapping(value = "/createParameterCatalog")
public Integer createParameterCatalog(@RequestBody ParameterCatalog parameterCatalog,
HttpServletResponse response) throws Exception{
String message = null;
if(parameterCatalog.getId()==null) {
message = "新增台账目录:{}";
}else {
message = "修改台账目录:{}";
}
try {
parameterCatalog = parameterService.saveOrUpdateCatalog(parameterCatalog);
} catch (Exception e) {
response.sendError(500);
throw new Exception(e.getMessage());
}
LogManager.logInfo(Constants.LOG_INDICATOR_PARAMETER_API,message,parameterCatalog.getCatalogName());
return parameterCatalog.getId();
}
@ApiOperation(value = "批量级联删除台账目录", notes = "批量级联删除台账目录")
@PostMapping(value = "/deleteParameterCatalog")
public void deleteParameterCatalog(@RequestParam List<Integer> ids) throws Exception{
StringBuilder message = new StringBuilder("");
List<ParameterCatalog> indCatalogs = parameterService.getByCatalogIdList(ids);
for(ParameterCatalog indCatalog : indCatalogs) {
message.append(indCatalog.getCatalogName()).append(";");
}
parameterService.recursionDelete(ids);
LogManager.logInfo(Constants.LOG_INDICATOR_PARAMETER_API,"删除台账目录:{}",message.toString());
}
@ApiOperation(value = "获取台账目录", notes = "获取台账目录")
@PostMapping(value = "/getParameterCatalog")
public List<ParameterCatalog> getParameterCatalog(@RequestParam(required=false) Integer parentId,
@RequestParam List<String> codes){
if(parentId==null) {
parentId = 0;
}
return parameterService.getCatalog(parentId, codes);
}
@ApiOperation(value = "根据关键字搜索获取台账目录", notes = "根据关键字搜索获取台账目录")
@PostMapping(value = "/getParameterCatalogByKeyword")
public List<ParameterCatalog> getParameterCatalogByKeyword(@RequestParam(required=false) String keyword,
@RequestParam List<String> codes){
return parameterService.getCatalogByKeyword(keyword,codes);
}
@ApiOperation(value = "获取第一个有效的台账目录节点", notes = "获取第一个有效的台账目录节点")
@PostMapping(value = "/getFirstVaildParameterCatalog")
public ParameterCatalog getFirstVaildParameterCatalog(@RequestParam Integer pid,
@RequestParam List<String> codes){
return parameterService.getFirstVaildCatalog(pid, codes);
}
@ApiOperation(value = "根据台账目录id数列获取台账目录List", notes = "根据台账目录id数列获取台账目录List")
@PostMapping(value = "/getByParameterCatalogIdList")
public List<ParameterCatalog> getByParameterCatalogIdList(@RequestParam List<Integer> catalogIds){
return parameterService.getByCatalogIdList(catalogIds);
}
@ApiOperation(value = "新建或者修改台账数据(isUpdate:0 新增 1修改)", notes = "新建或者修改台账数据(isUpdate:0 新增 1修改)")
@PostMapping(value = "/createParameterData")
public String createBaseInd(@RequestBody ParameterData parameterData,@RequestParam Integer catalogId,
@RequestParam String catalogIdPath,@RequestParam String user,
@RequestParam String isUpdate,@RequestParam String code,
HttpServletResponse response) throws Exception{
String result = null;
try {
result = parameterService.saveOrUpdate(parameterData, catalogId, catalogIdPath, user, isUpdate, code);
if("0".equals(isUpdate)) {
LogManager.logInfo(Constants.LOG_INDICATOR_PARAMETER_API,"新增台账数据:{}",parameterData.getParameterObj());
}else {
LogManager.logInfo(Constants.LOG_INDICATOR_PARAMETER_API,"修改台账数据:{}",parameterData.getParameterObj());
}
} catch (Exception e) {
response.sendError(500);
throw new Exception(e.getMessage());
}
return result;
}
@ApiOperation(value = "删除台账数据", notes = "删除台账数据")
@PostMapping(value = "/deleteParameterData")
public void deleteParameterData(@RequestParam List<Integer> ids) throws Exception{
StringBuilder message = new StringBuilder("");
List<ParameterData> baseIndDefs = parameterService.getByIdList(ids);
for(ParameterData baseIndDef : baseIndDefs) {
message.append(baseIndDef.getParameterObj()).append(";");
}
LogManager.logInfo(Constants.LOG_INDICATOR_PARAMETER_API,"删除台账数据:{}",message.toString());
parameterService.delete(ids);
}
@ApiOperation(value = "根据id查询台账数据详情", notes = "根据id查询台账数据详情")
@PostMapping(value = "/getParameterDataById")
public ParameterData getParameterDataById(@RequestParam Integer id) throws Exception{
return parameterService.getById(id);
}
@ApiOperation(value = "根据关键字分页查询台账数据", notes = "根据关键字分页查询台账数据")
@PostMapping(value = "/getByPageAndKeyword")
public Map<String,Object> getByPageAndKeyword(@RequestParam Integer catalogId,
@RequestParam(required=false) String keyword,
@RequestParam(defaultValue = "0") int page,@RequestParam(defaultValue = "10") int rows) throws Exception{
return parameterService.getByPageAndKeyword(catalogId, keyword, page, rows);
}
}
...@@ -23,6 +23,8 @@ public class Constants { ...@@ -23,6 +23,8 @@ public class Constants {
public static final String LOG_INDICATOR_SHORTBOARD_RULE_API = "indicator.shortboardrule"; public static final String LOG_INDICATOR_SHORTBOARD_RULE_API = "indicator.shortboardrule";
public static final String LOG_INDICATOR_SHORTBOARD_UNIT_API = "indicator.shortboardunit"; public static final String LOG_INDICATOR_SHORTBOARD_UNIT_API = "indicator.shortboardunit";
public static final String LOG_INDICATOR_PARAMETER_API = "indicator.parameter";
/** collection Name */ /** collection Name */
......
package com.keymobile.indicators.model.entity.parameter;
import java.util.Date;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import com.keymobile.indicators.utils.DateUtils;
import lombok.Data;
/**
*author:zhangkb time:2020-9-23 desc:台账目录
*/
@Data
@Table(name="parameter_catalog")
public class ParameterCatalog {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String catalogName;//台账目录名称
private String catalogType;//0:普通目录 1:台账目录
private Integer parentId;//顶层节点parentId为0
private String idPath;//目录idPath
private String parameterObjName;//台账对象名称,如果选了catalogType为1的类型可以选填
private String code;//目录编码
private String lastUpdater;//最后修改人
private String lastUpdateTime = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss");//最后修改时间
}
package com.keymobile.indicators.model.entity.parameter;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import lombok.Data;
/**
*author:zhangkb time:2020-9-23 desc:台账数据
*/
@Data
@Table(name="parameter_data")
public class ParameterData {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String parameterObj;//台账对象
private String parameterNum;//台账对象编号
private String parameterDate;//台账日期(yyyy-MM-dd)
private String scoreType;//积分类型
private Double score;//积分
private String inputDate;//输入日期
private String catalogIdPath;//台账目录idPath
private Integer catalogId;//台账目录id
private String creater;//创建者
private String createTime;//创建时间
private String updater;//修改者
private String updateTime;//修改时间
private String code;//机构编码
}
package com.keymobile.indicators.model.mapper.parameter;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import com.keymobile.indicators.model.entity.parameter.ParameterCatalog;
import tk.mybatis.mapper.common.BaseMapper;
@Mapper
public interface ParameterCatalogMapper extends BaseMapper<ParameterCatalog>{
public void deleteByIdIn(@Param("ids")List<Integer> ids);
public List<ParameterCatalog> findByParentIdAndCodeInOrderByLastUpdateTimeDesc(Map<String,Object> params);
public List<ParameterCatalog> findByParentId(@Param("pid") Integer pid);
public List<ParameterCatalog> findByKeyword(Map<String,Object> params);
public List<ParameterCatalog> findFirstVaildCatalog(Map<String,Object> params);
public List<ParameterCatalog> findByCatalogIdIn(@Param("ids") List<Integer> ids);
public List<ParameterCatalog> findByCatalogTypeAndCode(Map<String,Object> params);
public List<ParameterCatalog> findIsExist(@Param("catalogName") String catalogName,
@Param("parentId") Integer parentId,@Param("code") String code);
}
package com.keymobile.indicators.model.mapper.parameter;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import com.keymobile.indicators.model.entity.parameter.ParameterData;
import tk.mybatis.mapper.common.BaseMapper;
@Mapper
public interface ParameterDataMapper extends BaseMapper<ParameterData>{
public void deleteByCatalogIdIn(@Param("catalogIds")List<Integer> catalogIds);
public void deleteByIdIn(@Param("ids")List<Integer> ids);
public int getByKeywordCount(Map<String,Object> param);
public List<ParameterData> getPageByKeyword(Map<String,Object> param);
public List<ParameterData> getByIdList(@Param("ids")List<Integer> ids);
}
package com.keymobile.indicators.service.parameter;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.keymobile.indicators.model.entity.parameter.ParameterCatalog;
import com.keymobile.indicators.model.entity.parameter.ParameterData;
import com.keymobile.indicators.model.mapper.parameter.ParameterCatalogMapper;
import com.keymobile.indicators.model.mapper.parameter.ParameterDataMapper;
import com.keymobile.indicators.utils.DateUtils;
@Service
public class ParameterService {
private Logger logger = LoggerFactory.getLogger(ParameterService.class);
@Autowired
private ParameterCatalogMapper parameterCatalogMapper;
@Autowired
private ParameterDataMapper parameterDataMapper;
public ParameterCatalog saveOrUpdateCatalog(ParameterCatalog paramCatalog) throws Exception{
if(paramCatalog.getId()==null) {//新增
if(!parameterCatalogMapper.findIsExist(paramCatalog.getCatalogName(), paramCatalog.getParentId(),
paramCatalog.getCode()).isEmpty()) {
throw new Exception("名称重复,请重新输入!");
}
//保存
parameterCatalogMapper.insert(paramCatalog);
}else {
List<ParameterCatalog> dbList = parameterCatalogMapper.findIsExist(paramCatalog.getCatalogName(),
paramCatalog.getParentId(),paramCatalog.getCode());
if(!dbList.isEmpty() && !dbList.get(0).getId().equals(paramCatalog.getId())) {
throw new Exception("名称重复,请重新输入!");
}
}
//获取parentId拼接idPath
int parentId = paramCatalog.getParentId();
if(parentId==0) {//顶层节点
paramCatalog.setIdPath(String.valueOf(paramCatalog.getId())+";");
}else {
ParameterCatalog parentIndCatalog = parameterCatalogMapper.selectByPrimaryKey(
paramCatalog.getParentId());
if(parentIndCatalog==null) {
throw new Exception("父节点不存在:parent catalog is not exist");
}else {
paramCatalog.setIdPath(parentIndCatalog.getIdPath()+paramCatalog.getId()+";");
}
}
//保存
parameterCatalogMapper.updateByPrimaryKey(paramCatalog);
return paramCatalog;
}
public void delete(List<Integer> ids) {
parameterCatalogMapper.deleteByIdIn(ids);
}
//递归查找父目录下的子目录
public List<Integer> getDeleteCatalogId(int id){
List<Integer> result = new ArrayList<>();
result.add(id);
//根据id获取子节点
List<ParameterCatalog> children = parameterCatalogMapper.findByParentId(id);
if(!children.isEmpty()) {
for(ParameterCatalog child : children) {
result.addAll(getDeleteCatalogId(child.getId()));
}
}
return result;
}
//递归删除
public void recursionDelete(List<Integer> ids) {
List<Integer> result = new ArrayList<>();
for(Integer id : ids) {
result.addAll(this.getDeleteCatalogId(id));
}
if(!result.isEmpty()) {
this.delete(result);
//删除目录关联的台账数据
parameterDataMapper.deleteByCatalogIdIn(result);
}
}
//获取目录树
public List<ParameterCatalog> getCatalog(Integer parentId,List<String> codes){
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("pid", parentId);
paramMap.put("codes", codes);
return parameterCatalogMapper.findByParentIdAndCodeInOrderByLastUpdateTimeDesc(paramMap);
}
//根据目录树获取
public List<ParameterCatalog> getCatalogByKeyword(String keyword,List<String> codes){
if(StringUtils.isBlank(keyword)) {
return new ArrayList<>();
}
Map<String,Object> params = new HashMap<>();
params.put("keyword", "%"+keyword+"%");
params.put("codes", codes);
return parameterCatalogMapper.findByKeyword(params);
}
//获取第一个有效目录节点
public ParameterCatalog getFirstVaildCatalog(Integer pid,List<String> codes) {
Map<String,Object> params = new HashMap<>();
params.put("pidPath", pid+";"+"%");
params.put("codes", codes);
List<ParameterCatalog> resultList = parameterCatalogMapper.findFirstVaildCatalog(params);
if(!resultList.isEmpty()) {
return resultList.get(0);
}
return null;
}
public List<ParameterCatalog> getByCatalogIdList(List<Integer> catalogIds){
return parameterCatalogMapper.findByCatalogIdIn(catalogIds);
}
/**-----------台账数据操作-----------**/
//isUpdate:0 新建 1 修改
public String saveOrUpdate(ParameterData parameterData,Integer catalogId,
String catalogIdPath,String user,String isUpdate,String code) throws Exception{
if("0".equals(isUpdate)) {//新建
parameterData.setCreater(user);
parameterData.setCreateTime(DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss"));
parameterData.setUpdater(user);
parameterData.setUpdateTime(DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss"));
parameterData.setCode(code);
parameterData.setCatalogId(catalogId);
parameterData.setCatalogIdPath(catalogIdPath);
parameterDataMapper.insert(parameterData);
}else {
if(parameterData.getId()==null) {
throw new Exception("修改台账的id不能为空");
}else {
//查看数据库是否存在
ParameterData dbParameterData = parameterDataMapper.selectByPrimaryKey(parameterData.getId());
if(dbParameterData!=null) {
parameterData.setUpdater(user);
parameterData.setUpdateTime(DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss"));
parameterData.setCode(code);
parameterData.setCatalogId(catalogId);
parameterData.setCatalogIdPath(catalogIdPath);
parameterDataMapper.updateByPrimaryKey(parameterData);
}else {
throw new Exception("不存在台账id为:"+parameterData.getId()+" 的台账数据,无法修改");
}
}
}
return "parameterDataId:"+parameterData.getId();
}
public ParameterData getById(Integer id) throws Exception{
return parameterDataMapper.selectByPrimaryKey(id);
}
public List<ParameterData> getByIdList(List<Integer> ids) throws Exception{
return parameterDataMapper.getByIdList(ids);
}
public void deleteParameterData(List<Integer> ids) throws Exception{
parameterDataMapper.deleteByIdIn(ids);
}
public Map<String,Object> getByPageAndKeyword(Integer catalogId,String keyword,
int page,int rows)throws Exception{
Map<String,Object> resultMap = new HashMap<>();
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("catalogId", catalogId);
if(StringUtils.isBlank(keyword)) {
paramMap.put("keyword", null);
}else {
paramMap.put("keyword", "%"+keyword+"%");
}
//计算总数
int count = parameterDataMapper.getByKeywordCount(paramMap);
//计算start
int start = page*rows;
paramMap.put("start", start);
paramMap.put("end", rows);
List<ParameterData> resultList = parameterDataMapper.getPageByKeyword(paramMap);
resultMap.put("resultList", resultList);
resultMap.put("total", count);
return resultMap;
}
}
...@@ -42,6 +42,9 @@ ...@@ -42,6 +42,9 @@
<logger name="indicator.shortboardunit"> <logger name="indicator.shortboardunit">
<appender-ref ref="db" /> <appender-ref ref="db" />
</logger> </logger>
<logger name="indicator.parameter">
<appender-ref ref="db" />
</logger>
<root level="INFO"> <root level="INFO">
<appender-ref ref="stdout" /> <appender-ref ref="stdout" />
</root> </root>
......
<?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.keymobile.indicators.model.mapper.parameter.ParameterCatalogMapper">
<delete id="deleteByIdIn" parameterType="java.util.List">
delete
from parameter_catalog
where id in
<foreach item="id" collection="ids" open="(" close=")" separator=",">
#{id}
</foreach>
</delete>
<select id="findByParentIdAndCodeInOrderByLastUpdateTimeDesc" parameterType="map" resultType="com.keymobile.indicators.model.entity.parameter.ParameterCatalog" >
select *
from parameter_catalog
where parent_id = #{pid} and
code in
<foreach item="id" collection="codes" open="(" close=")" separator=",">
#{id}
</foreach>
order by last_update_time desc
</select>
<select id="findByParentId" resultType="com.keymobile.indicators.model.entity.parameter.ParameterCatalog" >
select *
from parameter_catalog
where parent_id = #{pid}
</select>
<select id="findByKeyword" resultType="com.keymobile.indicators.model.entity.parameter.ParameterCatalog" >
select *
from parameter_catalog
where catalog_name like #{keyword} and
code in
<foreach item="id" collection="codes" open="(" close=")" separator=",">
#{id}
</foreach>
</select>
<select id="findFirstVaildCatalog" resultType="com.keymobile.indicators.model.entity.parameter.ParameterCatalog" >
select *
from parameter_catalog
where id_path like #{pidPath} and
catalog_type = '1' and
code in
<foreach item="id" collection="codes" open="(" close=")" separator=",">
#{id}
</foreach>
order by last_update_time asc
</select>
<select id="findByCatalogIdIn" resultType="com.keymobile.indicators.model.entity.parameter.ParameterCatalog" >
select *
from parameter_catalog
where
id in
<foreach item="id" collection="ids" open="(" close=")" separator=",">
#{id}
</foreach>
</select>
<select id="findByCatalogTypeAndCode" parameterType="map" resultType="com.keymobile.indicators.model.entity.parameter.ParameterCatalog" >
select *
from parameter_catalog
where
catalog_type=#{type} and
code in
<foreach item="id" collection="codes" open="(" close=")" separator=",">
#{id}
</foreach>
</select>
<select id="findIsExist" resultType="com.keymobile.indicators.model.entity.parameter.ParameterCatalog" >
select *
from parameter_catalog
where
catalog_name=#{catalogName} and
parent_id=#{parentId} and
code=#{code}
</select>
</mapper>
\ No newline at end of file
<?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.keymobile.indicators.model.mapper.parameter.ParameterDataMapper">
<delete id="deleteByCatalogIdIn" parameterType="java.util.List">
delete
from parameter_data
where catalog_id in
<foreach item="id" collection="catalogIds" open="(" close=")" separator=",">
#{id}
</foreach>
</delete>
<delete id="deleteByIdIn" parameterType="java.util.List">
delete
from parameter_data
where id in
<foreach item="id" collection="ids" open="(" close=")" separator=",">
#{id}
</foreach>
</delete>
<select id="getPageByKeyword" parameterType="map" resultType="com.keymobile.indicators.model.entity.parameter.ParameterData" >
select *
from parameter_data
where 1=1
<if test="catalogId!=null">
and catalog_id = #{catalogId}
</if>
<if test="keyword!=null">
and parameter_obj like #{keyword}
</if>
limit #{start},#{end}
</select>
<select id="getByKeywordCount" parameterType="map" resultType="java.lang.Integer">
select count(1)
from parameter_data
where 1=1
<if test="catalogId!=null">
and catalog_id = #{catalogId}
</if>
<if test="keyword!=null">
and parameter_obj like #{keyword}
</if>
</select>
<select id="getByIdList" parameterType="java.util.List" resultType="com.keymobile.indicators.model.entity.parameter.ParameterData">
select *
from parameter_data
where id in
<foreach item="id" collection="ids" open="(" close=")" separator=",">
#{id}
</foreach>
</select>
</mapper>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment