Commit 589d6ffc by zhangkb

提交分析指标curd操作接口

parent 7710f241
...@@ -13,8 +13,10 @@ import com.keymobile.indicators.model.entity.IndAcsDef; ...@@ -13,8 +13,10 @@ import com.keymobile.indicators.model.entity.IndAcsDef;
import com.keymobile.indicators.service.cmbkpi.GeneralParmService; import com.keymobile.indicators.service.cmbkpi.GeneralParmService;
import com.keymobile.indicators.service.cmbkpi.IndAcsDefService; import com.keymobile.indicators.service.cmbkpi.IndAcsDefService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@Api(tags={"考核指标接口"})
@RestController @RestController
@RequestMapping(value = "/indAcs") @RequestMapping(value = "/indAcs")
public class IndAcsDefCtrl { public class IndAcsDefCtrl {
......
package com.keymobile.indicators.api.cmbkpi;
import java.util.Date;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
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.model.entity.IndAnaDef;
import com.keymobile.indicators.service.cmbkpi.IndAnaDefService;
import com.keymobile.indicators.utils.DateUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@Api(tags={"分析指标接口"})
@RestController
@RequestMapping(value = "/indAna")
public class IndAnaDefCtrl {
@Autowired
private IndAnaDefService indAnaDefService;
@ApiOperation(value = "保存或修改分析指标(defTime和updTime格式:yyyy-MM-dd HH:mm:ss)",
notes = "保存或修改分析指标(defTime和updTime格式:yyyy-MM-dd HH:mm:ss)")
@PostMapping(value = "/saveOrUpdate")
public String saveOrUpdate(@RequestBody IndAnaDef indAnaDef,
@RequestParam(required=false) String defTime,
@RequestParam(required=false) String updTime) throws Exception{
if(StringUtils.isNotBlank(defTime)) {
Date defDate = DateUtils.getDate(defTime, "yyyy-MM-dd HH:mm:ss");
indAnaDef.setDefTime(defDate);
}
if(StringUtils.isNotBlank(updTime)) {
Date updDate = DateUtils.getDate(updTime, "yyyy-MM-dd HH:mm:ss");
indAnaDef.setUpdTime(updDate);
}
return indAnaDefService.saveOrUpdate(indAnaDef);
}
@ApiOperation(value = "删除分析指标", notes = "删除分析指标")
@PostMapping(value = "/delete")
public void delete(@RequestParam String indId) throws Exception{
indAnaDefService.delete(indId);
}
@ApiOperation(value = "根据关键字分页获取分析指标列表(page:0 开始)", notes = "根据关键字分页获取分析指标列表(page:0 开始)")
@PostMapping(value = "/getPageListByKeyword")
public Map<String,Object> getPageListByKeyword(
@RequestParam(required=false) String keyword,
@RequestParam int page,
@RequestParam int rows) throws Exception{
return indAnaDefService.getByPageAndKeyword(keyword, page, rows);
}
}
package com.keymobile.indicators.model.mapper; package com.keymobile.indicators.model.mapper;
import java.util.List;
import java.util.Map;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
@Mapper import com.keymobile.indicators.model.entity.IndAnaDef;
public interface IndAnaDefMapper {
import tk.mybatis.mapper.common.BaseMapper;
@Mapper
public interface IndAnaDefMapper extends BaseMapper<IndAnaDef>{
public List<IndAnaDef> getPageByKeyword(Map<String,Object> param);
public int getByKeywordCount(Map<String,Object> param);
} }
package com.keymobile.indicators.service.cmbkpi; package com.keymobile.indicators.service.cmbkpi;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.keymobile.indicators.model.entity.IndAnaDef;
import com.keymobile.indicators.model.mapper.IndAnaDefMapper; import com.keymobile.indicators.model.mapper.IndAnaDefMapper;
@Service @Service
public class IndAnaDefService { public class IndAnaDefService {
@Autowired @Autowired
private IndAnaDefMapper indAnaDefMapper; private IndAnaDefMapper indAnaDefMapper;
public String saveOrUpdate(IndAnaDef indAnaDef) throws Exception{
if(StringUtils.isBlank(indAnaDef.getIndId())) {
return "indId can not be null";
}
//根据指标编号判断分析指标是否已存在
IndAnaDef dbIndAnaDef = this.getById(indAnaDef.getIndId());
if(dbIndAnaDef==null) {
indAnaDefMapper.insert(indAnaDef);
}else {
indAnaDefMapper.updateByPrimaryKey(indAnaDef);
}
return indAnaDef.getIndId();
}
public void delete(String indId) throws Exception{
indAnaDefMapper.deleteByPrimaryKey(indId);
}
public IndAnaDef getById(String id) throws Exception{
IndAnaDef anaDef = new IndAnaDef();
anaDef.setIndId(id);
return indAnaDefMapper.selectOne(anaDef);
}
public Map<String,Object> getByPageAndKeyword(String keyword,int page,int rows)throws Exception{
Map<String,Object> paramMap = new HashMap<>();
Map<String,Object> resultMap = new HashMap<>();
if(StringUtils.isBlank(keyword)) {
paramMap.put("keyword", null);
}else {
paramMap.put("keyword", "%"+keyword+"%");
}
//计算总数
int count = indAnaDefMapper.getByKeywordCount(paramMap);
//计算start
int start = page*rows;
paramMap.put("start", start);
paramMap.put("end", rows);
List<IndAnaDef> resultList = indAnaDefMapper.getPageByKeyword(paramMap);
resultMap.put("resultList", resultList);
resultMap.put("total", count);
return resultMap;
}
} }
package com.keymobile.indicators.utils;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateUtils {
public static Date getDate(String dateStr,String format) throws Exception{
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
Date date = simpleDateFormat.parse(dateStr);
return date;
}
}
<?xml version="1.0" encoding="UTF-8"?> <?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"> <!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.IndAnaDefMapper"> <mapper namespace="com.keymobile.indicators.model.mapper.IndAnaDefMapper">
<select id="getPageByKeyword" parameterType="map" resultType="com.keymobile.indicators.model.entity.IndAnaDef" >
select * from ind_ana_ind_def_inf
<if test="keyword!=null">
where ind_name like #{keyword} or ind_id like #{keyword}
</if>
limit #{start},#{end}
</select>
<select id="getByKeywordCount" parameterType="map" resultType="java.lang.Integer">
select count(1) from ind_ana_ind_def_inf
<if test="keyword!=null">
where ind_name like #{keyword} or ind_id like #{keyword}
</if>
</select>
</mapper> </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