Commit 868d7f64 by 张祺

添加数据填报的业务实现

parent 4b06f9d9
package com.keymobile.indicators.api.hytobacco;
import com.keymobile.indicators.constant.Constants;
import com.keymobile.indicators.model.entity.dataenter.*;
import com.keymobile.indicators.result.Result;
import com.keymobile.indicators.service.dataenter.ExcelTemplateService;
import com.keymobile.indicators.service.dataenter.TaskService;
import com.keymobile.indicators.utils.IdWorker;
import com.keymobile.indicators.utils.SystemUserUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Api(tags={"数据填报-在线填报、excel导入"})
@RestController
@RequestMapping(value = "/dataenter")
@Slf4j
public class DataEnterCtrl {
@Autowired
private TaskService taskService;
@Autowired
private ExcelTemplateService excelTemplateService;
@ApiOperation("获取需要在线填报的数据项")
@GetMapping("findToEdit")
public List<TaskIndValue> findToEdit(@RequestParam("taskId") String taskId) {
List<TaskIndValue> list = new ArrayList<>();
Task task = taskService.getById(taskId);
String userId = SystemUserUtil.getCurrentUserId();
String orgId = SystemUserUtil.getCurrentUserOrgId();
String orgName = SystemUserUtil.getCurrentUserOrgName();
List<TaskIndicator> taskIndicators = task.getIndicators();
if (CollectionUtils.isNotEmpty(taskIndicators)) {
List<TaskIndValue> oldValues = taskService.findValues(taskId, Constants.INPUT_ONLINE);
if (CollectionUtils.isEmpty(oldValues)) {
//新增
List<String> indIds = new ArrayList<>();
for (TaskIndicator indicator : taskIndicators) {
indIds.add(indicator.getIndId());
}
List<TaskIndValue> defaultValues = taskService.findDefaultValues(task.getValueTime(), indIds);
list = genernateEditObjects(task, defaultValues, orgId, orgName, Constants.OBJ_TYPE_ORG);
} else {
list = genernateEditObjects(task, oldValues, orgId, orgName, Constants.OBJ_TYPE_ORG);
}
}
return list;
}
/**
* 生成填写对象
* @param task
* @param oldValues
* @param objId
* @param objName
* @param objType
* @return
*/
private List<TaskIndValue> genernateEditObjects(Task task, List<TaskIndValue> oldValues,
String objId, String objName, Integer objType) {
List<TaskIndValue> list = new ArrayList<>();
List<TaskIndicator> taskIndicators = task.getIndicators();
for (TaskIndicator indicator : taskIndicators) {
if (indicator.getIndSource() == Constants.INPUT_ONLINE) {
TaskIndValue value = new TaskIndValue();
value.setIndId(indicator.getIndId());
value.setIndName(indicator.getIndName());
value.setValueTime(task.getValueTime());
value.setIndUnit(indicator.getIndUnit());
value.setObjId(objId);
value.setObjName(objName);
value.setObjType(objType);
for (TaskIndValue old : oldValues) {
if (old.getIndId().equals(value.getIndId())
&& old.getObjType().equals(value.getObjType())
&& old.getObjId().equals(value.getObjId())) {
value.setIndValue(old.getIndValue());
break;
}
}
list.add(value);
}
}
return list;
}
@ApiOperation("填报数据保存")
@PostMapping("saveData")
public Result saveData(@RequestBody List<TaskIndValue> values, @RequestParam("taskId") String taskId) {
Date now = new Date();
String userId = SystemUserUtil.getCurrentUserId();
Task task = taskService.getById(taskId);
for (TaskIndValue value : values) {
value.setId(IdWorker.getStrId());
value.setTaskId(taskId);
value.setValueTime(task.getValueTime());
value.setState(Constants.DATA_STATE_A);
value.setCreateTime(now);
value.setCreator(userId);
value.setUpdater(userId);
value.setUpdateTime(now);
}
taskService.saveTaskValues(values, taskId, Constants.INPUT_ONLINE);
return Result.genOkResult();
}
@ApiOperation("填报数据保存")
@PostMapping("importData")
public Result importData(@RequestParam("file") MultipartFile file, @ApiParam("所属任务") @RequestParam("taskId") String taskId) {
String userId = SystemUserUtil.getCurrentUserId();
Result result = null;
Date now = new Date();
try {
InputStream is = file.getInputStream();
XSSFWorkbook xssfWorkbook = new XSSFWorkbook(is);
ExcelTemplate template = excelTemplateService.getByTaskId(taskId);
List<ExcelIndicator> inds = template.getInds();
List<ExcelObj> objs = template.getObjs();
} catch (Exception e) {
log.error("数据填报导入出错:taskId=" + taskId , e);
result = Result.genFailedResult("导入excel出错");
}
return result;
}
}
...@@ -4,9 +4,11 @@ import com.google.gson.Gson; ...@@ -4,9 +4,11 @@ import com.google.gson.Gson;
import com.keymobile.indicators.model.entity.dataenter.ExcelTemplate; import com.keymobile.indicators.model.entity.dataenter.ExcelTemplate;
import com.keymobile.indicators.result.Result; import com.keymobile.indicators.result.Result;
import com.keymobile.indicators.service.dataenter.ExcelTemplateService; import com.keymobile.indicators.service.dataenter.ExcelTemplateService;
import com.keymobile.indicators.utils.SystemUserUtil;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -17,7 +19,7 @@ import java.util.HashMap; ...@@ -17,7 +19,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@Api(tags={"填报excel模板"}) @Api(tags={"数据填报-填报excel模板管理"})
@RestController @RestController
@RequestMapping(value = "/excel") @RequestMapping(value = "/excel")
public class ExcelTempCtrl { public class ExcelTempCtrl {
...@@ -29,19 +31,34 @@ public class ExcelTempCtrl { ...@@ -29,19 +31,34 @@ public class ExcelTempCtrl {
@GetMapping("findByTaskRule") @GetMapping("findByTaskRule")
public List<ExcelTemplate> findByTaskRule(@ApiParam(name = "ruleId", required = false) @RequestParam("ruleId")Integer ruleId, public List<ExcelTemplate> findByTaskRule(@ApiParam(name = "ruleId", required = false) @RequestParam("ruleId")Integer ruleId,
@ApiParam(name = "taskId", required = false) @RequestParam("taskId")String taskId) { @ApiParam(name = "taskId", required = false) @RequestParam("taskId")String taskId) {
return null; return excelTemplateService.findByRuleTask(ruleId, taskId);
} }
@ApiOperation("根据任务id获取excel模板") @ApiOperation("根据任务id获取excel模板")
@GetMapping("findByTaskId") @GetMapping("findByTaskId")
public ExcelTemplate findByTaskId(@ApiParam(name = "taskId") @RequestParam("taskId")String taskId) { public ExcelTemplate findByTaskId(@ApiParam(name = "taskId") @RequestParam("taskId")String taskId) {
return null; return excelTemplateService.getByTaskId(taskId);
} }
@ApiOperation("关联任务到现有的模板")
@GetMapping("refToTaskId")
public Result refTempalteToTaskId(@ApiParam(name = "模板id") @RequestParam("templateId")Integer templateId,
@ApiParam(name = "任务id") @RequestParam("taskId")String taskId) {
excelTemplateService.createTemplateFromOld(templateId, taskId, SystemUserUtil.getCurrentUserId());
return Result.genOkResult();
}
@ApiOperation("保存excel模板") @ApiOperation("保存excel模板")
@PostMapping("save") @PostMapping("save")
public Result save(@RequestBody ExcelTemplate template) { public Result save(@RequestBody ExcelTemplate template) {
if (template.getId() == null) { if (StringUtils.isNotBlank(template.getTaskId())) {
ExcelTemplate temp = excelTemplateService.getByTaskId(template.getTaskId());
if (temp != null && !temp.getId().equals(template.getId())) {
return Result.genFailedResult("该任务已经存在设置好的模板!");
}
}
if (template.getId() == null || template.getId() == 0) {
excelTemplateService.create(template); excelTemplateService.create(template);
} else { } else {
excelTemplateService.update(template); excelTemplateService.update(template);
...@@ -52,13 +69,14 @@ public class ExcelTempCtrl { ...@@ -52,13 +69,14 @@ public class ExcelTempCtrl {
@ApiOperation("根据id获取excel模板") @ApiOperation("根据id获取excel模板")
@GetMapping("getById") @GetMapping("getById")
public ExcelTemplate getById(@RequestParam("id")Integer id) { public ExcelTemplate getById(@RequestParam("id")Integer id) {
return null; return excelTemplateService.getById(id);
} }
@ApiOperation("id删除excel模板") @ApiOperation("id删除excel模板")
@GetMapping("deleteById") @GetMapping("deleteById")
public Result deleteById(@RequestParam("id")Integer id) { public Result deleteById(@RequestParam("id")Integer id) {
return null; excelTemplateService.delete(id);
return Result.genOkResult();
} }
@ApiOperation("根据id导出excel") @ApiOperation("根据id导出excel")
...@@ -67,8 +85,8 @@ public class ExcelTempCtrl { ...@@ -67,8 +85,8 @@ public class ExcelTempCtrl {
try { try {
response.setContentType("application/vnd.ms-excel"); response.setContentType("application/vnd.ms-excel");
response.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8");
ExcelTemplate template = excelTemplateService.getById(id);
String fileName = URLEncoder.encode("", "UTF-8"); String fileName = URLEncoder.encode(template.getName(), "UTF-8");
response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
} catch (Exception e) { } catch (Exception e) {
response.reset(); response.reset();
......
...@@ -3,6 +3,7 @@ package com.keymobile.indicators.api.hytobacco; ...@@ -3,6 +3,7 @@ package com.keymobile.indicators.api.hytobacco;
import com.keymobile.indicators.model.entity.dataenter.QueryTaskParam; import com.keymobile.indicators.model.entity.dataenter.QueryTaskParam;
import com.keymobile.indicators.model.entity.dataenter.Task; import com.keymobile.indicators.model.entity.dataenter.Task;
import com.keymobile.indicators.model.entity.dataenter.TaskAssginParam; import com.keymobile.indicators.model.entity.dataenter.TaskAssginParam;
import com.keymobile.indicators.model.entity.dataenter.TaskAuditResult;
import com.keymobile.indicators.result.Result; import com.keymobile.indicators.result.Result;
import com.keymobile.indicators.service.dataenter.TaskRuleService; import com.keymobile.indicators.service.dataenter.TaskRuleService;
import com.keymobile.indicators.service.dataenter.TaskService; import com.keymobile.indicators.service.dataenter.TaskService;
...@@ -13,7 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -13,7 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@Api(tags={"填报任务相关接口"}) @Api(tags={"数据填报-填报任务管理"})
@RestController @RestController
@RequestMapping(value = "/task") @RequestMapping(value = "/task")
public class TaskCtrl { public class TaskCtrl {
...@@ -51,5 +52,18 @@ public class TaskCtrl { ...@@ -51,5 +52,18 @@ public class TaskCtrl {
return null; return null;
} }
@ApiOperation("提交任务去审核")
@PostMapping("toSubmit")
public Result toSubmit(@ApiParam(name = "任务id") @RequestParam String id) {
return Result.genOkResult();
}
@ApiOperation("审核任务")
@PostMapping("audit")
public Result audit(@ApiParam(name = "任务id") @RequestBody TaskAuditResult param) {
return Result.genOkResult();
}
} }
...@@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.*; ...@@ -14,7 +14,7 @@ import org.springframework.web.bind.annotation.*;
import java.util.Date; import java.util.Date;
@Api(tags={"填报任务规则管理接口"}) @Api(tags={"数据填报-任务规则管理"})
@RestController @RestController
@RequestMapping(value = "/taskRule") @RequestMapping(value = "/taskRule")
public class TaskRuleCtrl { public class TaskRuleCtrl {
......
...@@ -73,4 +73,29 @@ public class Constants { ...@@ -73,4 +73,29 @@ public class Constants {
*/ */
public static final int DATA_STATE_X = 3; public static final int DATA_STATE_X = 3;
/**
* 数据项数据来源- excel填报-1
*/
public static final int INPUT_EXCEL = 1;
/**
* 数据项数据来源- 在线填报-2
*/
public static final int INPUT_ONLINE = 2;
/**
* 数据项数据来源- 接口填报-3
*/
public static final int INPUT_INTERFACE = 3;
/**
* 对象类型- 组织机构-1
*/
public static final int OBJ_TYPE_ORG = 1;
/**
* 对象类型- 组织机构-2
*/
public static final int OBJ_TYPE_USER = 2;
} }
...@@ -25,11 +25,6 @@ public class ExcelIndicator extends BaseModel { ...@@ -25,11 +25,6 @@ public class ExcelIndicator extends BaseModel {
private Integer tempId; private Integer tempId;
/** /**
* 方向 1:纵向、2:横向
*/
private Integer orientation;
/**
* 关联指标id * 关联指标id
*/ */
private String indId; private String indId;
......
...@@ -25,11 +25,6 @@ public class ExcelObj extends BaseModel { ...@@ -25,11 +25,6 @@ public class ExcelObj extends BaseModel {
private Integer tempId; private Integer tempId;
/** /**
* 方向 1:纵向、2:横向
*/
private Integer orientation;
/**
* 对象id * 对象id
*/ */
private String objId; private String objId;
......
...@@ -22,6 +22,12 @@ public class ExcelTemplate extends BaseModel { ...@@ -22,6 +22,12 @@ public class ExcelTemplate extends BaseModel {
private String name; private String name;
/** /**
* 列类型
*/
@ApiModelProperty("列类型:1、指标 2 考核对象")
private Integer cType;
/**
* 任务规则id * 任务规则id
*/ */
private Integer ruleId; private Integer ruleId;
......
package com.keymobile.indicators.model.entity.dataenter;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ApiModel("任务审批参数")
@Data
public class TaskAuditResult {
/**
* 审批的任务id
*/
@ApiModelProperty("审批的任务id")
private String taskId;
@ApiModelProperty("审批结果:true 通过 false 驳回")
private boolean result = true;
@ApiModelProperty("审批结果意见描述")
private String description;
}
package com.keymobile.indicators.model.entity.dataenter; package com.keymobile.indicators.model.entity.dataenter;
import com.keymobile.indicators.model.entity.BaseModel; import com.keymobile.indicators.model.entity.BaseModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import javax.persistence.Id; import javax.persistence.Id;
...@@ -34,11 +35,13 @@ public class TaskIndValue extends BaseModel { ...@@ -34,11 +35,13 @@ public class TaskIndValue extends BaseModel {
/** /**
* 指标名称 * 指标名称
*/ */
@ApiModelProperty("指标名称")
private String indName; private String indName;
/** /**
* 指标单位 * 指标单位
*/ */
@ApiModelProperty("指标单位")
private String indUnit; private String indUnit;
/** /**
...@@ -47,36 +50,41 @@ public class TaskIndValue extends BaseModel { ...@@ -47,36 +50,41 @@ public class TaskIndValue extends BaseModel {
private Integer indSource; private Integer indSource;
/** /**
* 数据项单位
*/
private String unit;
/**
* 指标值 * 指标值
*/ */
@ApiModelProperty("指标值")
private String indValue; private String indValue;
/** /**
* 数据时间,例如2020-06表示二季度 * 数据时间,例如2020-06表示二季度
*/ */
@ApiModelProperty("数据时间")
private String valueTime; private String valueTime;
/** /**
* 数据对象id * 数据对象id
*/ */
@ApiModelProperty("数据对象id")
private String objId; private String objId;
/** /**
* 数据对象类型:1、组织机构 2、人员 * 数据对象类型:1、组织机构 2、人员
*/ */
@ApiModelProperty("数据对象类型:1、组织机构 2、人员")
private Integer objType; private Integer objType;
/** /**
* 数据项名称 * 数据项对象名称
*/ */
@ApiModelProperty("数据对象名称")
private String objName; private String objName;
/** /**
* excel导入对应的excel模板id * excel导入对应的excel模板id
*/ */
private Integer tempId; private Integer tempId;
/**
* 填报状态:3 审核通过
*/
private Integer status;
} }
...@@ -22,4 +22,10 @@ public interface ExcelIndicatorMapper extends BaseMapper<ExcelIndicator> { ...@@ -22,4 +22,10 @@ public interface ExcelIndicatorMapper extends BaseMapper<ExcelIndicator> {
* @param tempId * @param tempId
*/ */
void deleteByTempId(Integer tempId); void deleteByTempId(Integer tempId);
/**
* 根据模板id逻辑删除指标信息
* @param tempId
*/
void deleteLogisByTempId(Integer tempId);
} }
...@@ -21,4 +21,10 @@ public interface ExcelObjMapper extends BaseMapper<ExcelObj> { ...@@ -21,4 +21,10 @@ public interface ExcelObjMapper extends BaseMapper<ExcelObj> {
* @param tempId * @param tempId
*/ */
void deleteByTempId(Integer tempId); void deleteByTempId(Integer tempId);
/**
* 根据模板id逻辑删除考核对象信息
* @param tempId
*/
void deleteLogisByTempId(Integer tempId);
} }
...@@ -2,8 +2,11 @@ package com.keymobile.indicators.model.mapper.indicators; ...@@ -2,8 +2,11 @@ package com.keymobile.indicators.model.mapper.indicators;
import com.keymobile.indicators.model.entity.dataenter.ExcelTemplate; import com.keymobile.indicators.model.entity.dataenter.ExcelTemplate;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import tk.mybatis.mapper.common.BaseMapper; import tk.mybatis.mapper.common.BaseMapper;
import java.util.List;
@Mapper @Mapper
public interface ExcelTemplateMapper extends BaseMapper<ExcelTemplate> { public interface ExcelTemplateMapper extends BaseMapper<ExcelTemplate> {
...@@ -12,4 +15,19 @@ public interface ExcelTemplateMapper extends BaseMapper<ExcelTemplate> { ...@@ -12,4 +15,19 @@ public interface ExcelTemplateMapper extends BaseMapper<ExcelTemplate> {
* @param id * @param id
*/ */
void deleteById(Integer id); void deleteById(Integer id);
/**
* 根据任务id获取excel模板
* @param taskId
* @return
*/
ExcelTemplate getByTaskId(String taskId);
/**
* 根据任务id获取excel模板
* @param ruleId
* @param taskId
* @return
*/
List<ExcelTemplate> findByRuleTask(@Param("ruleId") Integer ruleId, @Param("taskId") String taskId);
} }
...@@ -2,6 +2,7 @@ package com.keymobile.indicators.model.mapper.indicators; ...@@ -2,6 +2,7 @@ package com.keymobile.indicators.model.mapper.indicators;
import com.keymobile.indicators.model.entity.dataenter.TaskIndValue; import com.keymobile.indicators.model.entity.dataenter.TaskIndValue;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import tk.mybatis.mapper.common.BaseMapper; import tk.mybatis.mapper.common.BaseMapper;
import java.util.List; import java.util.List;
...@@ -10,6 +11,12 @@ import java.util.List; ...@@ -10,6 +11,12 @@ import java.util.List;
public interface TaskIndValueMapper extends BaseMapper<TaskIndValue> { public interface TaskIndValueMapper extends BaseMapper<TaskIndValue> {
/** /**
* 批量插入填报值
* @param valueList
*/
void batchInsert(List<TaskIndValue> valueList);
/**
* 根据任务id获取填报数据项值 * 根据任务id获取填报数据项值
* @param taskId * @param taskId
* @return * @return
...@@ -21,4 +28,27 @@ public interface TaskIndValueMapper extends BaseMapper<TaskIndValue> { ...@@ -21,4 +28,27 @@ public interface TaskIndValueMapper extends BaseMapper<TaskIndValue> {
* @param taskId * @param taskId
*/ */
void deleteByTaskId(String taskId); void deleteByTaskId(String taskId);
/**
* 任务id删除已填报的数据项值
* @param taskId
* @param indSource 数据来源: 1、excel导入 2、手工填报 3、接口导入
*/
void deleteByTaskAndSource(@Param("taskId") String taskId, @Param("indSource") Integer indSource);
/**
* 根据任务id和数据来源类型获取已经填报的指标值
* @param taskId
* @param indSource
* @return
*/
List<TaskIndValue> findValuesByTaskAndSource(@Param("taskId")String taskId, @Param("indSource") Integer indSource);
/**
* 根据数据时间和指标ids来源获取填报审核通过的指标值
* @param valueTime
* @param ids
* @return
*/
List<TaskIndValue> findDefaultValues(@Param("valueTime")String valueTime, @Param("ids") List<String> ids);
} }
...@@ -17,6 +17,14 @@ public interface ExcelTemplateService { ...@@ -17,6 +17,14 @@ public interface ExcelTemplateService {
int create(ExcelTemplate template); int create(ExcelTemplate template);
/** /**
* 关联任务到现有的模板
* @param templateId
* @param taskId
* @param userId
*/
void createTemplateFromOld(Integer templateId, String taskId, String userId);
/**
* 根据id获取 * 根据id获取
* @param id * @param id
* @return * @return
......
...@@ -2,6 +2,7 @@ package com.keymobile.indicators.service.dataenter; ...@@ -2,6 +2,7 @@ package com.keymobile.indicators.service.dataenter;
import com.keymobile.indicators.model.entity.dataenter.QueryTaskParam; import com.keymobile.indicators.model.entity.dataenter.QueryTaskParam;
import com.keymobile.indicators.model.entity.dataenter.Task; import com.keymobile.indicators.model.entity.dataenter.Task;
import com.keymobile.indicators.model.entity.dataenter.TaskIndValue;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import java.util.List; import java.util.List;
...@@ -67,4 +68,27 @@ public interface TaskService { ...@@ -67,4 +68,27 @@ public interface TaskService {
Page<Task> findTask(QueryTaskParam param); Page<Task> findTask(QueryTaskParam param);
/**
* 保存填报数据
* @param values
* @param taskId
* @param indSource
*/
void saveTaskValues(List<TaskIndValue> values, String taskId, Integer indSource);
/**
* 根据任务id和数据来源类型获取已经填报的数据值
* @param taskId
* @param indSource
* @return
*/
List<TaskIndValue> findValues(String taskId, Integer indSource);
/**
* 根据填报时间和指标ids获取已经审批通过的数据作为已填报值
* @param valueTime
* @param indIds
* @return
*/
List<TaskIndValue> findDefaultValues(String valueTime, List<String> indIds);
} }
package com.keymobile.indicators.service.dataenter.impl; package com.keymobile.indicators.service.dataenter.impl;
import com.keymobile.indicators.constant.Constants;
import com.keymobile.indicators.model.entity.dataenter.ExcelIndicator;
import com.keymobile.indicators.model.entity.dataenter.ExcelObj;
import com.keymobile.indicators.model.entity.dataenter.ExcelTemplate; import com.keymobile.indicators.model.entity.dataenter.ExcelTemplate;
import com.keymobile.indicators.model.mapper.indicators.ExcelIndicatorMapper;
import com.keymobile.indicators.model.mapper.indicators.ExcelObjMapper;
import com.keymobile.indicators.model.mapper.indicators.ExcelTemplateMapper; import com.keymobile.indicators.model.mapper.indicators.ExcelTemplateMapper;
import com.keymobile.indicators.service.dataenter.ExcelTemplateService; import com.keymobile.indicators.service.dataenter.ExcelTemplateService;
import com.keymobile.indicators.utils.SystemUserUtil;
import org.apache.commons.collections.CollectionUtils;
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 org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.List; import java.util.List;
@Service @Service
...@@ -14,33 +23,137 @@ public class ExcelTemplateServiceImpl implements ExcelTemplateService { ...@@ -14,33 +23,137 @@ public class ExcelTemplateServiceImpl implements ExcelTemplateService {
@Autowired @Autowired
private ExcelTemplateMapper excelTemplateMapper; private ExcelTemplateMapper excelTemplateMapper;
@Autowired
private ExcelObjMapper excelObjMapper;
@Autowired
private ExcelIndicatorMapper excelIndicatorMapper;
@Override @Override
@Transactional(rollbackFor = Exception.class)
public int create(ExcelTemplate template) { public int create(ExcelTemplate template) {
return excelTemplateMapper.insert(template); Date now = new Date();
String currentUserId = SystemUserUtil.getCurrentUserId();
template.setUpdater(currentUserId);
template.setCreator(currentUserId);
template.setUpdateTime(now);
template.setCreateTime(now);
template.setState(Constants.DATA_STATE_A);
int result = excelTemplateMapper.insert(template);
insertIndAndObj(template, now, currentUserId);
return result;
} }
@Override @Override
public ExcelTemplate getById(Integer id) { @Transactional(rollbackFor = Exception.class)
return excelTemplateMapper.selectByPrimaryKey(id); public void createTemplateFromOld(Integer templateId, String taskId, String userId) {
Date now = new Date();
ExcelTemplate t = excelTemplateMapper.getByTaskId(taskId);
if (t != null) {
this.delete(t.getId());
}
ExcelTemplate temp = excelTemplateMapper.selectByPrimaryKey(templateId);
temp.setId(null);
temp.setTaskId(taskId);
temp.setUpdateTime(now);
temp.setCreateTime(now);
temp.setCreator(userId);
temp.setUpdater(userId);
excelTemplateMapper.insert(temp);
insertIndAndObj(temp, now, userId);
} }
@Override @Override
public ExcelTemplate getByTaskId(String taskId) { @Transactional(rollbackFor = Exception.class)
return null; public void update(ExcelTemplate template) {
Date now = new Date();
String currentUserId = SystemUserUtil.getCurrentUserId();
ExcelTemplate temp = excelTemplateMapper.selectByPrimaryKey(template.getId());
temp.setUpdater(currentUserId);
temp.setUpdateTime(now);
temp.setInds(template.getInds());
temp.setObjs(template.getObjs());
temp.setName(template.getName());
excelTemplateMapper.updateByPrimaryKey(temp);
excelIndicatorMapper.deleteByTempId(template.getId());
excelObjMapper.deleteByTempId(template.getId());
insertIndAndObj(temp, now, currentUserId);
}
/**
* 插入指标和对象信息
* @param template
* @param now
* @param currentUserId
*/
private void insertIndAndObj(ExcelTemplate template, Date now, String currentUserId) {
List<ExcelObj> objs = template.getObjs();
if (CollectionUtils.isNotEmpty(objs)) {
int o = 1;
for (ExcelObj obj : objs) {
obj.setId(null);
obj.setTempId(template.getId());
obj.setUpdater(currentUserId);
obj.setCreator(currentUserId);
obj.setUpdateTime(now);
obj.setOrderNum(o++);
obj.setCreateTime(now);
obj.setState(Constants.DATA_STATE_A);
excelObjMapper.insert(obj);
}
}
List<ExcelIndicator> inds =template.getInds();
if (CollectionUtils.isNotEmpty(inds)) {
int o = 1;
for (ExcelIndicator indicator : inds) {
indicator.setId(null);
indicator.setUpdater(currentUserId);
indicator.setCreator(currentUserId);
indicator.setUpdateTime(now);
indicator.setCreateTime(now);
indicator.setOrderNum(o++);
indicator.setState(Constants.DATA_STATE_A);
indicator.setTempId(template.getId());
excelIndicatorMapper.insert(indicator);
}
}
} }
@Override @Override
public List<ExcelTemplate> findByRuleTask(Integer ruleId, String taskId) { public ExcelTemplate getById(Integer id) {
return null; ExcelTemplate template = excelTemplateMapper.selectByPrimaryKey(id);
if (template != null) {
List<ExcelObj> objs = excelObjMapper.getByTempId(id);
List<ExcelIndicator> inds = excelIndicatorMapper.getByTempId(id);
template.setObjs(objs);
template.setInds(inds);
}
return template;
} }
@Override @Override
public void update(ExcelTemplate template) { public ExcelTemplate getByTaskId(String taskId) {
ExcelTemplate template = excelTemplateMapper.getByTaskId(taskId);
if (template != null) {
List<ExcelObj> objs = excelObjMapper.getByTempId(template.getId());
List<ExcelIndicator> inds = excelIndicatorMapper.getByTempId(template.getId());
template.setObjs(objs);
template.setInds(inds);
}
return template;
}
@Override
public List<ExcelTemplate> findByRuleTask(Integer ruleId, String taskId) {
return excelTemplateMapper.findByRuleTask(ruleId, taskId);
} }
@Override @Override
@Transactional(rollbackFor = Exception.class)
public void delete(Integer id) { public void delete(Integer id) {
excelTemplateMapper.deleteById(id);
excelObjMapper.deleteLogisByTempId(id);
excelIndicatorMapper.deleteLogisByTempId(id);
} }
} }
...@@ -3,10 +3,13 @@ package com.keymobile.indicators.service.dataenter.impl; ...@@ -3,10 +3,13 @@ package com.keymobile.indicators.service.dataenter.impl;
import com.keymobile.indicators.constant.Constants; import com.keymobile.indicators.constant.Constants;
import com.keymobile.indicators.model.entity.dataenter.QueryTaskParam; import com.keymobile.indicators.model.entity.dataenter.QueryTaskParam;
import com.keymobile.indicators.model.entity.dataenter.Task; import com.keymobile.indicators.model.entity.dataenter.Task;
import com.keymobile.indicators.model.entity.dataenter.TaskIndValue;
import com.keymobile.indicators.model.entity.dataenter.TaskIndicator; import com.keymobile.indicators.model.entity.dataenter.TaskIndicator;
import com.keymobile.indicators.model.mapper.indicators.TaskIndValueMapper;
import com.keymobile.indicators.model.mapper.indicators.TaskIndicatorMapper; import com.keymobile.indicators.model.mapper.indicators.TaskIndicatorMapper;
import com.keymobile.indicators.model.mapper.indicators.TaskMapper; import com.keymobile.indicators.model.mapper.indicators.TaskMapper;
import com.keymobile.indicators.service.dataenter.TaskService; import com.keymobile.indicators.service.dataenter.TaskService;
import com.keymobile.indicators.utils.IdWorker;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
...@@ -16,6 +19,7 @@ import org.springframework.stereotype.Service; ...@@ -16,6 +19,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
@Service @Service
...@@ -27,6 +31,9 @@ public class TaskServiceImpl implements TaskService { ...@@ -27,6 +31,9 @@ public class TaskServiceImpl implements TaskService {
@Autowired @Autowired
private TaskIndicatorMapper taskIndicatorMapper; private TaskIndicatorMapper taskIndicatorMapper;
@Autowired
private TaskIndValueMapper taskIndValueMapper;
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public Task createTask(Task task) { public Task createTask(Task task) {
...@@ -97,4 +104,21 @@ public class TaskServiceImpl implements TaskService { ...@@ -97,4 +104,21 @@ public class TaskServiceImpl implements TaskService {
Page<Task> pageResult = new PageImpl<Task>(list, request, total); Page<Task> pageResult = new PageImpl<Task>(list, request, total);
return pageResult; return pageResult;
} }
@Override
@Transactional(rollbackFor = Exception.class)
public void saveTaskValues(List<TaskIndValue> values, String taskId, Integer indSource) {
taskIndValueMapper.deleteByTaskAndSource(taskId, indSource);
taskIndValueMapper.batchInsert(values);
}
@Override
public List<TaskIndValue> findValues(String taskId, Integer indSource) {
return taskIndValueMapper.findValuesByTaskAndSource(taskId, indSource);
}
@Override
public List<TaskIndValue> findDefaultValues(String valueTime, List<String> indIds) {
return taskIndValueMapper.findDefaultValues(valueTime, indIds);
}
} }
package com.keymobile.indicators.utils;
import java.util.UUID;
/**
* <p>
* 高效GUID产生算法(sequence),基于Snowflake实现64位自增ID算法。 <br>
* </p>
*
*/
public class IdWorker {
/**
* 主机和进程的机器码
*/
private static Sequence worker = new Sequence();
/**
* 生成id
* @return
*/
public static long getId() {
return worker.nextId();
}
/**
* 生成序列id
* @return
*/
public static String getStrId() {
return String.valueOf(getId());
}
/**
* <p>
* 获取去掉"-" UUID
* </p>
*/
public static synchronized String get32UUID() {
return UUID.randomUUID().toString().replace("-", "");
}
}
package com.keymobile.indicators.utils;
import javax.servlet.http.HttpServletRequest;
import java.net.InetAddress;
import java.net.UnknownHostException;
/**
* 获取IP工具类
* @author laigx
* @version 1.0
* @date 2020/3/25 14:51
*/
public class IpUtil {
/**
* 获取IP
* @param request request
* @return IP
*/
public static String getIpAddr(HttpServletRequest request) {
String ipAddress;
try {
ipAddress = request.getHeader("x-forwarded-for");
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getHeader("Proxy-Client-IP");
}
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getHeader("WL-Proxy-Client-IP");
}
if (ipAddress == null || ipAddress.length() == 0 || "unknown".equalsIgnoreCase(ipAddress)) {
ipAddress = request.getRemoteAddr();
if ("127.0.0.1".equals(ipAddress)) {
try {
InetAddress inet = InetAddress.getLocalHost();
ipAddress = inet.getHostAddress();
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
}
if (ipAddress != null && ipAddress.length() > 15) {
if (ipAddress.indexOf(",") > 0) {
ipAddress = ipAddress.substring(0, ipAddress.indexOf(","));
}
}
} catch (Exception e) {
ipAddress = "";
}
return ipAddress;
}
}
package com.keymobile.indicators.utils;
import org.apache.commons.lang3.StringUtils;
import java.lang.management.ManagementFactory;
import java.net.InetAddress;
import java.net.NetworkInterface;
/**
* 基于Twitter的Snowflake算法实现分布式高效有序ID生产黑科技(sequence)
*
* <br>
* SnowFlake的结构如下(每部分用-分开):<br>
* <br>
* 0 - 0000000000 0000000000 0000000000 0000000000 0 - 00000 - 00000 - 000000000000 <br>
* <br>
* 1位标识,由于long基本类型在Java中是带符号的,最高位是符号位,正数是0,负数是1,所以id一般是正数,最高位是0<br>
* <br>
* 41位时间截(毫秒级),注意,41位时间截不是存储当前时间的时间截,而是存储时间截的差值(当前时间截 - 开始时间截)
* 得到的值),这里的的开始时间截,一般是我们的id生成器开始使用的时间,由我们程序来指定的(如下下面程序IdWorker类的startTime属性)。41位的时间截,可以使用69年,年T = (1L << 41) / (1000L * 60 * 60 * 24 * 365) = 69<br>
* <br>
* 10位的数据机器位,可以部署在1024个节点,包括5位datacenterId和5位workerId<br>
* <br>
* 12位序列,毫秒内的计数,12位的计数顺序号支持每个节点每毫秒(同一机器,同一时间截)产生4096个ID序号<br>
* <br>
* <br>
* 加起来刚好64位,为一个Long型。<br>
* SnowFlake的优点是,整体上按照时间自增排序,并且整个分布式系统内不会产生ID碰撞(由数据中心ID和机器ID作区分),并且效率较高,经测试,SnowFlake每秒能够产生26万ID左右。
*
* @author lry
*/
public class Sequence {
/** 开始时间截 */
private final long twepoch = 1288834974657L;
/** 机器id所占的位数 */
private final long workerIdBits = 5L;
/** 数据标识id所占的位数 */
private final long datacenterIdBits = 5L;
/** 支持的最大机器id,结果是31 (这个移位算法可以很快的计算出几位二进制数所能表示的最大十进制数) */
private final long maxWorkerId = -1L ^ (-1L << workerIdBits);
/** 支持的最大数据标识id,结果是31 */
private final long maxDatacenterId = -1L ^ (-1L << datacenterIdBits);
/** 序列在id中占的位数 */
private final long sequenceBits = 12L;
/** 机器ID向左移12位 */
private final long workerIdShift = sequenceBits;
/** 数据标识id向左移17位(12+5) */
private final long datacenterIdShift = sequenceBits + workerIdBits;
/** 时间截向左移22位(5+5+12) */
private final long timestampLeftShift = sequenceBits + workerIdBits + datacenterIdBits;
/** 生成序列的掩码,这里为4095 (0b111111111111=0xfff=4095) */
private final long sequenceMask = -1L ^ (-1L << sequenceBits);
/** 工作机器ID(0~31) */
private long workerId;
/** 数据中心ID(0~31) */
private long datacenterId;
/** 毫秒内序列(0~4095) */
private long sequence = 0L;
/** 上次生成ID的时间截 */
private long lastTimestamp = -1L;
/**
* 默认算法
*/
public Sequence() {
this.datacenterId = getDatacenterId(maxDatacenterId);
this.workerId = getMaxWorkerId(datacenterId, maxWorkerId);
}
/**
* @param workerId 工作ID (0~31)
* @param datacenterId 数据中心ID (0~31)
*/
public Sequence(long workerId, long datacenterId) {
if (workerId > maxWorkerId || workerId < 0) {
throw new IllegalArgumentException(String.format("worker Id can't be greater than %d or less than 0", maxWorkerId));
}
if (datacenterId > maxDatacenterId || datacenterId < 0) {
throw new IllegalArgumentException(String.format("datacenter Id can't be greater than %d or less than 0", maxDatacenterId));
}
this.workerId = workerId;
this.datacenterId = datacenterId;
}
/**
* 获得下一个ID (该方法是线程安全的)
*
* @return
*/
public synchronized long nextId() {
long timestamp = timeGen();
// 如果当前时间小于上一次ID生成的时间戳,说明系统时钟回退过这个时候应当抛出异常
if (timestamp < lastTimestamp) {// 闰秒
long offset = lastTimestamp - timestamp;
if (offset <= 5) {
try {
wait(offset << 1);
timestamp = timeGen();
if (timestamp < lastTimestamp) {
throw new RuntimeException(String.format("Clock moved backwards. Refusing to generate id for %d milliseconds", offset));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
} else {
throw new RuntimeException(String.format("Clock moved backwards. Refusing to generate id for %d milliseconds", offset));
}
}
//$NON-NLS-解决跨毫秒生成ID序列号始终为偶数的缺陷$
// 如果是同一时间生成的,则进行毫秒内序列
if (lastTimestamp == timestamp) {
sequence = (sequence + 1) & sequenceMask;
// 毫秒内序列溢出
if (sequence == 0) {
// 阻塞到下一个毫秒,获得新的时间戳
timestamp = tilNextMillis(lastTimestamp);
}
} else {// 时间戳改变,毫秒内序列重置
sequence = 0L;
}
/**
// 如果是同一时间生成的,则进行毫秒内序列
if (lastTimestamp == timestamp) {
long old = sequence;
sequence = (sequence + 1) & sequenceMask;
// 毫秒内序列溢出
if (sequence == old) {
// 阻塞到下一个毫秒,获得新的时间戳
timestamp = tilNextMillis(lastTimestamp);
}
} else {// 时间戳改变,毫秒内序列重置
sequence = ThreadLocalRandom.current().nextLong(0, 2);
}
**/
// 上次生成ID的时间截
lastTimestamp = timestamp;
// 移位并通过或运算拼到一起组成64位的ID
return ((timestamp - twepoch) << timestampLeftShift) //
| (datacenterId << datacenterIdShift) //
| (workerId << workerIdShift) //
| sequence;
}
/**
* 阻塞到下一个毫秒,直到获得新的时间戳
*
* @param lastTimestamp 上次生成ID的时间截
* @return 当前时间戳
*/
protected long tilNextMillis(long lastTimestamp) {
long timestamp = timeGen();
while (timestamp <= lastTimestamp) {
timestamp = timeGen();
}
return timestamp;
}
/**
* 返回以毫秒为单位的当前时间
*
* @return 当前时间(毫秒)
*/
protected long timeGen() {
return SystemClock.now();
}
/**
* <p>
* 获取 maxWorkerId
* </p>
*/
protected static long getMaxWorkerId(long datacenterId, long maxWorkerId) {
StringBuffer mpid = new StringBuffer();
mpid.append(datacenterId);
String name = ManagementFactory.getRuntimeMXBean().getName();
if (StringUtils.isNotBlank(name)) {
/*
* GET jvmPid
*/
mpid.append(name.split("@")[0]);
}
/*
* MAC + PID 的 hashcode 获取16个低位
*/
return (mpid.toString().hashCode() & 0xffff) % (maxWorkerId + 1);
}
/**
* <p>
* 数据标识id部分
* </p>
*/
protected static long getDatacenterId(long maxDatacenterId) {
long id = 0L;
try {
InetAddress ip = InetAddress.getLocalHost();
NetworkInterface network = NetworkInterface.getByInetAddress(ip);
if (network == null) {
id = 1L;
} else {
byte[] mac = network.getHardwareAddress();
id = ((0x000000FF & (long) mac[mac.length - 1]) | (0x0000FF00 & (((long) mac[mac.length - 2]) << 8))) >> 6;
id = id % (maxDatacenterId + 1);
}
} catch (Exception e) {
}
return id;
}
}
\ No newline at end of file
package com.keymobile.indicators.utils;
import java.sql.Timestamp;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
/**
* 高并发场景下System.currentTimeMillis()的性能问题的优化
* <p><p>
* System.currentTimeMillis()的调用比new一个普通对象要耗时的多(具体耗时高出多少我还没测试过,有人说是100倍左右)<p>
* System.currentTimeMillis()之所以慢是因为去跟系统打了一次交道<p>
* 后台定时更新时钟,JVM退出时,线程自动回收<p>
* 10亿:43410,206,210.72815533980582%<p>
* 1亿:4699,29,162.0344827586207%<p>
* 1000万:480,12,40.0%<p>
* 100万:50,10,5.0%<p>
* @author lry
*/
public class SystemClock {
private final long period;
private final AtomicLong now;
private SystemClock(long period) {
this.period = period;
this.now = new AtomicLong(System.currentTimeMillis());
scheduleClockUpdating();
}
private static class InstanceHolder {
public static final SystemClock INSTANCE = new SystemClock(1);
}
private static SystemClock instance() {
return InstanceHolder.INSTANCE;
}
private void scheduleClockUpdating() {
ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() {
@Override
public Thread newThread(Runnable runnable) {
Thread thread = new Thread(runnable, "System Clock");
thread.setDaemon(true);
return thread;
}
});
scheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
now.set(System.currentTimeMillis());
}
}, period, period, TimeUnit.MILLISECONDS);
}
private long currentTimeMillis() {
return now.get();
}
public static long now() {
return instance().currentTimeMillis();
}
public static String nowDate() {
return new Timestamp(instance().currentTimeMillis()).toString();
}
}
...@@ -14,4 +14,22 @@ public class SystemUserUtil { ...@@ -14,4 +14,22 @@ public class SystemUserUtil {
return "1"; return "1";
} }
/**
* 获取当前登录用户所属组织id
* @return
*/
public static String getCurrentUserOrgId() {
//TODO 待实现
return "1";
}
/**
* 获取当前登录用户所属组织名称
* @return
*/
public static String getCurrentUserOrgName() {
//TODO 待实现
return "1";
}
} }
...@@ -2,11 +2,11 @@ ...@@ -2,11 +2,11 @@
<!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.indicators.ExcelIndicatorMapper"> <mapper namespace="com.keymobile.indicators.model.mapper.indicators.ExcelIndicatorMapper">
<select id="getByTempId" parameterType="java.lang.Integer" resultType="com.keymobile.indicators.model.entity.dataenter.ExcelIndicator" > <select id="getByTempId" parameterType="java.lang.Integer" resultType="com.keymobile.indicators.model.entity.dataenter.ExcelIndicator" >
select * select *
from data_enter_excel_ind from data_enter_excel_ind
where temp_id = #{tempId} where temp_id = #{tempId} and state = 1
order by order_num asc
</select> </select>
...@@ -15,4 +15,11 @@ ...@@ -15,4 +15,11 @@
from data_enter_excel_ind from data_enter_excel_ind
where temp_id = #{tempId} where temp_id = #{tempId}
</delete> </delete>
<update id="deleteLogisByTempId" parameterType="java.lang.Integer">
update data_enter_excel_ind
set state = 3
where temp_id = #{tempId}
</update>
</mapper> </mapper>
\ No newline at end of file
...@@ -6,7 +6,8 @@ ...@@ -6,7 +6,8 @@
<select id="getByTempId" parameterType="java.lang.Integer" resultType="com.keymobile.indicators.model.entity.dataenter.ExcelObj" > <select id="getByTempId" parameterType="java.lang.Integer" resultType="com.keymobile.indicators.model.entity.dataenter.ExcelObj" >
select * select *
from data_enter_excel_obj from data_enter_excel_obj
where temp_id = #{tempId} where temp_id = #{tempId} and state = 1
order by order_num asc
</select> </select>
...@@ -15,4 +16,11 @@ ...@@ -15,4 +16,11 @@
from data_enter_excel_obj from data_enter_excel_obj
where temp_id = #{tempId} where temp_id = #{tempId}
</delete> </delete>
<update id="deleteLogisByTempId" parameterType="java.lang.Integer">
update data_enter_excel_obj
set state = 3
where temp_id = #{tempId}
</update>
</mapper> </mapper>
\ No newline at end of file
...@@ -7,4 +7,24 @@ ...@@ -7,4 +7,24 @@
set state = 3 set state = 3
where id = #{id} where id = #{id}
</update> </update>
<select id="getByTaskId" parameterType="java.lang.String" resultType="com.keymobile.indicators.model.entity.dataenter.ExcelTemplate">
select *
from data_enter_excel_temp
where state = 1 and task_id = #{taskId}
limit 1
</select>
<select id="findByRuleTask" parameterType="object" resultType="com.keymobile.indicators.model.entity.dataenter.ExcelTemplate">
select *
from data_enter_excel_temp
where state = 1
<if test="ruleId != null and ruleId !=''">
and rule_id = #{ruleId}
</if>
<if test="taskId != null and taskId !=''">
and task_id = #{taskId}
</if>
order by update_time desc
</select>
</mapper> </mapper>
\ No newline at end of file
<?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.indicators.TaskIndValueMapper"> <mapper namespace="com.keymobile.indicators.model.mapper.indicators.TaskIndValueMapper">
<insert id="batchInsert" parameterType="list">
insert into data_enter_task_ind_val
(id,task_id,ind_id,ind_name,ind_unit,ind_source,ind_value,
value_time,obj_id,obj_name,obj_type,temp_id,status,
state,creator ,updater,create_time,update_time)
values
<foreach collection="valueList" item="val" separator=",">
(#{val.id},#{val.taskId}, #{val.indId}, #{val.indName}, #{val.indUnit}, #{val.indSource},#{val.indValue},
#{val.valueTime},#{val.objId},#{val.objName},#{val.objType}, #{tempId}, #{status},
#{val.state},#{val.creator},#{val.updater},#{val.createTime}, #{val.updateTime}
)
</foreach>
</insert>
<select id="getByTaskId" parameterType="java.lang.String" resultType="com.keymobile.indicators.model.entity.dataenter.TaskIndValue" > <select id="getByTaskId" parameterType="java.lang.String" resultType="com.keymobile.indicators.model.entity.dataenter.TaskIndValue" >
select * select *
...@@ -15,4 +28,37 @@ ...@@ -15,4 +28,37 @@
from data_enter_task_ind_val from data_enter_task_ind_val
where task_id = #{taskId} where task_id = #{taskId}
</delete> </delete>
<delete id="deleteByTaskAndSource" parameterType="object">
delete
from data_enter_task_ind_val
where task_id = #{taskId}
<if test="indSource != null">
and ind_source = #{indSource}
</if>
</delete>
<select id="findValuesByTaskAndSource" parameterType="object" resultType="com.keymobile.indicators.model.entity.dataenter.TaskIndValue" >
select *
from data_enter_task_ind_val
where task_id = #{taskId} and state = 1
<if test="indSource != null">
and ind_source = #{indSource}
</if>
</select>
<select id="findDefaultValues" parameterType="object" resultType="com.keymobile.indicators.model.entity.dataenter.TaskIndValue" >
select *
from data_enter_task_ind_val
where value_time = #{valueTime} and state = 1
and status = 3
<if test="ids != null and ids.size() > 0">
and ind_id in (
<foreach collection="ids" item="indId" separator=",">
#{indId}
</foreach>
)
</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