ganzi-api/inventory-ent/src/main/java/com/rzyc/service/PcBusinessService.java

704 lines
31 KiB
Java
Raw Normal View History

package com.rzyc.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.common.utils.*;
import com.common.utils.encryption.MD5;
import com.common.utils.model.Code;
import com.common.utils.model.Message;
import com.common.utils.model.SingleResult;
import com.common.utils.pager.PageOperation;
import com.github.pagehelper.Page;
import com.rzyc.config.RedisUtil;
import com.rzyc.controller.BaseController;
import com.rzyc.enums.RedisKeys;
import com.rzyc.model.*;
import com.rzyc.model.dto.*;
import com.rzyc.model.ent.EntPost;
import com.rzyc.model.ent.EntUser;
import com.rzyc.model.dto.SparePartDto;
import com.rzyc.model.ent.InEntList;
import com.rzyc.model.ent.SysEnterprise;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 企业端pc业务 Service
* @author Xuwanxin
* @date 2022/9/29
* */
@Service
public class PcBusinessService extends BaseController {
RedisUtil redisUtil;
@Autowired
public PcBusinessService(RedisUtil redisUtil) {
this.redisUtil = redisUtil;
}
public SingleResult entUserTree(String enterpriseId, String postId){
SingleResult singleResult = new SingleResult();
//读缓存get时候如果多级用:进行分隔
if (null != enterpriseId && postId == null){
List<EntPost> posts = (List<EntPost>) redisUtil.get(redisUtil.appendSymbol(RedisKeys.POST.getKey(),enterpriseId));
if (null != posts && posts.size() > 0 ){
singleResult.setData(posts);
return singleResult;
}
}else if (null != enterpriseId && postId != enterpriseId){
List<EntPost>posts = (List<EntPost>) redisUtil.get(redisUtil.appendSymbol(RedisKeys.POST.getKey(),enterpriseId,postId));
if (null != posts && posts.size() > 0 ){
singleResult.setData(posts);
return singleResult;
}
}
SysEnterprise sysEnterprise = sysEnterpriseMapper.selectByPrimaryKey(enterpriseId);
List<EntPost> list = entPostMapper.selectEntUserTree(enterpriseId,postId);
/**
* sql里进行了order by如果传入postId就是查询非全部的数结构需要加入一个公司所以把第一个最大权限设置为company这样公司才会在树的最上面
* 相反不穿postId就是查询全部默认会有company打头就不用再修改list的0对象
*/
//加入公司为第一个树结构
EntPost entPost = new EntPost();
entPost.setName(sysEnterprise.getEntname());
entPost.setPostId("company");
list.add(entPost);
if (null != postId){
list.get(0).setParentId("company");
}
JSONArray jsonArray = handleEntUserTree(list);
List<EntPost>posts = JSONArray.parseArray(JSONArray.toJSONString(jsonArray),EntPost.class);
singleResult.setData(posts);
//存入redis缓存
try {
if (null != enterpriseId && postId == null){
redisUtil.set(redisUtil.appendSymbol(RedisKeys.POST.getKey(),enterpriseId),posts,0);
}else if (null != enterpriseId && postId != enterpriseId){
redisUtil.set(redisUtil.appendSymbol(RedisKeys.POST.getKey(),postId,enterpriseId),posts,0);
}
}catch (Exception e){
e.printStackTrace();
}
return singleResult;
}
/**
* 处理企业用户数结构list
*/
private JSONArray handleEntUserTree(List<EntPost> list){
List<Map<String,Object>> data = new ArrayList<>();
for(EntPost entPost : list){
if(StringUtils.isBlank(entPost.getParentId())){
entPost.setParentId("");
}
Map<String,Object> entPostMap = new HashMap<String,Object>();
entPostMap.put("postId",entPost.getPostId());
entPostMap.put("name",entPost.getName());
entPostMap.put("parentId",entPost.getParentId());
entPostMap.put("subordinates",entPost.getSubordinates());
data.add(entPostMap);
}
com.alibaba.fastjson.JSONArray result = TypeConversion.listToTree(com.alibaba.fastjson.JSONArray.parseArray(JSON.toJSONString(data)),"postId","parentId","children");
return result;
}
public List<EntPostList> entUserPostList(EntUserPostListDto entUserPostListDto) throws Exception {
entUserPostListDto.setPostId(getUserPostId());
List<EntPostList>list = entPostListMapper.selectEntPostList(entUserPostListDto.getEnterpriseId(),entUserPostListDto.getEntUserId(),entUserPostListDto.getFinishedState(),
entUserPostListDto.getPostId(),entUserPostListDto.getPage(),entUserPostListDto.getPageSize());
return list;
}
public List<EntPostTask> entUserPostTask(EntUserPostTaskDto entUserPostTaskDto) throws Exception {
entUserPostTaskDto.setPostId(getUserPostId());
//当listId为null时默认第一个日常清单查询所有正在进行中的任务
if (null == entUserPostTaskDto.getListId()){
//2为正在进行中
entUserPostTaskDto.setTaskState(1);
}
//EntPostTask
List<EntPostTask>list = entPostTaskMapper.selectEntUserPostTask(entUserPostTaskDto.getEnterpriseId(),entUserPostTaskDto.getEntUserId(),entUserPostTaskDto.getPostId()
,entUserPostTaskDto.getListId(),entUserPostTaskDto.getContent(),entUserPostTaskDto.getTaskState());
return list;
}
public List entUserPostDuty(EntUserPostDutyDto entUserPostDutyDto) throws Exception {
entUserPostDutyDto.setPostId(getUserPostId());
//EntPostDuty
List<EntPostDuty>list = entPostDutyMapper.selectEntUserPostDuty(entUserPostDutyDto.getEnterpriseId(),entUserPostDutyDto.getPostId());
return list;
}
public SingleResult entUserCredential(String enterpriseId, String entUserId,Integer page,Integer pageSize){
SingleResult singleResult = new SingleResult();
page = pageSize * (page - 1);
List<EntUserCredential>list = entUserCredentialMapper.selectEntUserCredential(enterpriseId,entUserId,page,pageSize);
singleResult.setData(list);
return singleResult;
}
public SingleResult entUserCredentialUpdate(List<EntUserCredentialUpdateDto> entUserCredentialUpdateDto) throws Exception {
SingleResult singleResult = new SingleResult();
Integer result = 0;
for (EntUserCredentialUpdateDto e:entUserCredentialUpdateDto) {
EntUserCredential entUserCredential = new EntUserCredential();
BeanUtils.copyProperties(e,entUserCredential);
if (StringUtils.isNotBlank(entUserCredential.getCredentialId())) {
entUserCredential.setModifyBy(getUserId());
entUserCredential.setModifyTime(new Date());
result += entUserCredentialMapper.updateEntUserCredential(entUserCredential);
}else {
entUserCredential.setCredentialId(RandomNumber.getUUid());
entUserCredential.setCreateBy(getUserId());
entUserCredential.setCreateTime(new Date());
result += entUserCredentialMapper.insertEntUserCredential(entUserCredential);
}
}
if (result != entUserCredentialUpdateDto.size()){
singleResult.setCode(Code.ERROR.getCode());
singleResult.setMessage(Message.ERROR);
}
return singleResult;
}
public SingleResult entUserCredentialDelete(String credentialId){
SingleResult singleResult = new SingleResult();
int result = entUserCredentialMapper.entUserCredentialDelete(credentialId);
if (result==1){
singleResult.setCode(Code.SUCCESS.getCode());
singleResult.setMessage(Message.SUCCESS);
}
return singleResult;
}
public SingleResult entUserList(String keyContent,Integer page,Integer pageSize,String postId){
SingleResult singleResult = new SingleResult();
page = pageSize * (page - 1);
List<EntUser>users = entUserMapper.selectEntUserList(keyContent,page,pageSize,postId);
//计算履职百分比,后期这里使用redis来读取履职进度
for (EntUser e:users) {
Integer total = e.getFinishTask() + e.getOngoingTask() + e.getOverTimeTask();
double percent = Arith.div(total,e.getFinishTask()) * 100;
e.setEntUserTaskPercent(percent);
}
singleResult.setData(users);
return singleResult;
}
public SingleResult addOrUpdateEntUser(AddOrUpdateEntUserDto addOrUpdateEntUserDto) throws Exception {
SingleResult singleResult = new SingleResult();
//正则验证手机号
String regex = "^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\\d{8}$";
Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(addOrUpdateEntUserDto.getMobile());
if (!m.matches()){
singleResult.setCode(Code.ERROR.getCode());
singleResult.setMessage(Message.MOBILE_IS_ILLEGAL);
return singleResult;
}
//验证数据重复
EntUser entUser = new EntUser();
BeanUtils.copyProperties(addOrUpdateEntUserDto,entUser);
EntPost entPost = entPostMapper.selectById(addOrUpdateEntUserDto.getPostId());
entUser.setPostPath(entPost.getPostPath());
entUser.setPostPathName(entPost.getPostId());
//密码为用户名加手机号
entUser.setPasswd(MD5.md5(entUser.getName() + entUser.getMobile()));
int result = 0 ;
if (StringUtils.isNotBlank(entUser.getEntUserId())){
result = entUserMapper.updateEntUser(entUser);
}else {
result = entUserMapper.insert(entUser);
}
if (result != 1){
singleResult.setCode(Code.ERROR.getCode());
singleResult.setMessage(Message.ERROR);
}
//插入证件图
if (null != addOrUpdateEntUserDto.getEntUserCredentialUpdateDtos() && addOrUpdateEntUserDto.getEntUserCredentialUpdateDtos().size() > 0 ){
singleResult = this.entUserCredentialUpdate(addOrUpdateEntUserDto.getEntUserCredentialUpdateDtos());
}
return singleResult;
}
public SingleResult validEntUserMobile(String mobile, String entUserId){
SingleResult singleResult = new SingleResult();
//正则验证手机号
String regex = "^((13[0-9])|(14[5,7])|(15[0-3,5-9])|(17[0,3,5-8])|(18[0-9])|166|198|199|(147))\\d{8}$";
Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(mobile);
if (!m.matches()){
singleResult.setCode(Code.ERROR.getCode());
singleResult.setMessage(Message.MOBILE_IS_ILLEGAL);
return singleResult;
}
EntUser entUser = entUserMapper.validMobile(mobile);
if (entUser != null && !entUserId.equals(entUser.getEntUserId()) ){
singleResult.setCode(Code.ERROR.getCode());
singleResult.setMessage(Message.REGISTERED);
}
return singleResult;
}
public SingleResult validEntUserName(String name, String entUserId){
SingleResult singleResult = new SingleResult();
EntUser entUser = entUserMapper.validName(name);
if (entUser != null && !entUserId.equals(entUser.getEntUserId())){
singleResult.setCode(Code.ERROR.getCode());
singleResult.setMessage(Message.HAS_USERNAME);
}
return singleResult;
}
public SingleResult entEquipmentTypeList(String enterpriseId){
2022-10-18 11:36:52 +08:00
SingleResult singleResult = new SingleResult();
List<EntDeviceType> redisEntDeviceTypes =(List<EntDeviceType>) redisUtil.get(redisUtil.appendSymbol(RedisKeys.DEVICE.getKey(),enterpriseId));
if (null != redisEntDeviceTypes && redisEntDeviceTypes.size()>0){
singleResult.setData(redisEntDeviceTypes);
return singleResult;
}
List<EntDeviceType> entDeviceTypes = entDeviceTypeMapper.selectEntEquipmentTypeList(enterpriseId);
//树结构处理
JSONArray jsonArray = handleEntEquipment(entDeviceTypes);
List<EntPost>posts = JSONArray.parseArray(JSONArray.toJSONString(jsonArray),EntPost.class);
singleResult.setData(posts);
//存redis
boolean insertRedisResult = redisUtil.set(redisUtil.appendSymbol(RedisKeys.DEVICE.getKey(),enterpriseId),posts,0);
2022-10-18 11:36:52 +08:00
return singleResult;
}
/**
* 处理企业用户数结构list
*/
private JSONArray handleEntEquipment(List<EntDeviceType> list){
List<Map<String,Object>> data = new ArrayList<>();
for(EntDeviceType entDeviceType : list){
if(StringUtils.isBlank(entDeviceType.getParentId())){
entDeviceType.setParentId("");
}
Map<String,Object> entPostMap = new HashMap<String,Object>();
entPostMap.put("typeId",entDeviceType.getTypeId());
entPostMap.put("name",entDeviceType.getName());
entPostMap.put("parentId",entDeviceType.getParentId());
entPostMap.put("logo",entDeviceType.getLogo());
data.add(entPostMap);
}
com.alibaba.fastjson.JSONArray result = TypeConversion.listToTree(com.alibaba.fastjson.JSONArray.parseArray(JSON.toJSONString(data)),"typeId","parentId","children");
return result;
}
public Object entEquipmentList(String enterpriseId, String typeId,Integer page,Integer pageSize){
Page<EntDevice> devices = (Page<EntDevice>) entDeviceMapper.selectEntEquipmentList(enterpriseId,typeId);
return devices;
}
public SingleResult entEquipmentStatistic(String enterpriseId, String deviceId){
SingleResult singleResult = new SingleResult();
EntDevice data = entDeviceMapper.entEquipmentStatistic(enterpriseId,deviceId);
singleResult.setData(data);
return singleResult;
}
public SingleResult addOrUpdateEntPost(AddOrUpdateEntPostDto addOrUpdateEntPostDto) throws Exception {
SingleResult singleResult = new SingleResult();
EntPost entPost = new EntPost();
BeanUtils.copyProperties(addOrUpdateEntPostDto,entPost);
Integer result = 0;
if (null != addOrUpdateEntPostDto && null != addOrUpdateEntPostDto.getPostId()){
entPost.setModifyBy(getUserId());
entPost.setModifyTime(new Date());
result = entPostMapper.updateEntPost(entPost);
}else {
entPost.setPostId(RandomNumber.getUUid());
entPost.setCreateTime(new Date());
entPost.setCreateBy(getUserId());
result = entPostMapper.insertEntPost(entPost);
}
if (result != 1 ){
singleResult.setCode(Code.ERROR.getCode());
singleResult.setMessage(Message.ERROR);
}
return singleResult;
}
public SingleResult addOrUpdateEntEquipmentType(AddOrUpdateEntEquipmentTypeDto addOrUpdateEntEquipmentTypeDto) throws Exception {
SingleResult singleResult = new SingleResult();
EntDeviceType entDeviceType = new EntDeviceType();
BeanUtils.copyProperties(addOrUpdateEntEquipmentTypeDto,entDeviceType);
Integer result = 0;
if (null != addOrUpdateEntEquipmentTypeDto && null != addOrUpdateEntEquipmentTypeDto.getTypeId()){
entDeviceType.setModifyBy(getUserId());
entDeviceType.setModifyTime(new Date());
result = entDeviceTypeMapper.updateEntEquipment(entDeviceType);
}else {
entDeviceType.setCreateBy(getUserId());
entDeviceType.setCreateTime(new Date());
entDeviceType.setTypeId(RandomNumber.getUUid());
result = entDeviceTypeMapper.addEntEquipment(entDeviceType);
}
if (result != 1 ){
singleResult.setCode(Code.ERROR.getCode());
singleResult.setMessage(Message.ERROR);
}else {
//更新redis
List<EntDeviceType> entDeviceTypes = entDeviceTypeMapper.selectEntEquipmentTypeList(addOrUpdateEntEquipmentTypeDto.getEnterpriseId());
//树结构处理
JSONArray jsonArray = handleEntEquipment(entDeviceTypes);
List<EntPost>posts = JSONArray.parseArray(JSONArray.toJSONString(jsonArray),EntPost.class);
singleResult.setData(posts);
//存redis
boolean insertRedisResult = redisUtil.set(redisUtil.appendSymbol(RedisKeys.DEVICE.getKey(),addOrUpdateEntEquipmentTypeDto.getEnterpriseId()),posts,0);
}
return singleResult;
}
public SingleResult addOrUpdateEntEquipment(AddOrUpdateEntEquipmentDto addOrUpdateEntEquipmentDto) throws Exception {
SingleResult singleResult = new SingleResult();
EntDevice entDevice = new EntDevice();
BeanUtils.copyProperties(addOrUpdateEntEquipmentDto,entDevice);
Integer result = 0;
if (null != addOrUpdateEntEquipmentDto && null != addOrUpdateEntEquipmentDto.getDeviceId()){
entDevice.setModifyBy(getUserId());
entDevice.setModifyTime(new Date());
result = entDeviceMapper.updateEntDevice(entDevice);
}else {
entDevice.setCreateBy(getUserId());
entDevice.setCreateTime(new Date());
entDevice.setDeviceId(RandomNumber.getUUid());
result = entDeviceMapper.insert(entDevice);
}
if (result != 1 ){
singleResult.setCode(Code.ERROR.getCode());
singleResult.setMessage(Message.ERROR);
}
return singleResult;
}
public Object deviceInspectionCycle(String inspectionName,Integer page,Integer pageSize){
Page<EntDeviceInsCycle>list = (Page<EntDeviceInsCycle>) entDeviceInsCycleMapper.deviceInspectionCycle(inspectionName);
return list;
}
public SingleResult addOrUpdateDeviceInspectionCycle(AddOrUpdateDeviceInspectionCycleDto addOrUpdateDeviceInspectionCycleDto){
SingleResult singleResult = new SingleResult();
Integer result = 0;
EntDeviceInsCycle entDeviceInsCycle = new EntDeviceInsCycle();
BeanUtils.copyProperties(addOrUpdateDeviceInspectionCycleDto,entDeviceInsCycle);
if (null != addOrUpdateDeviceInspectionCycleDto && null != addOrUpdateDeviceInspectionCycleDto.getInspectionId()){
result = entDeviceInsCycleMapper.updateDeviceInspectionCycle(entDeviceInsCycle);
}else {
result = entDeviceInsCycleMapper.insert(entDeviceInsCycle);
}
if (result != 1 ){
singleResult.setCode(Code.ERROR.getCode());
singleResult.setMessage(Message.ERROR);
}
return singleResult;
}
public SingleResult addOrUpdateInspectionRecord(AddOrUpdateInspectionRecordDto addOrUpdateInspectionRecordDto){
SingleResult singleResult = new SingleResult();
EntInsRecord entInsRecord = new EntInsRecord();
BeanUtils.copyProperties(addOrUpdateInspectionRecordDto,entInsRecord);
int result = 0;
if (null != addOrUpdateInspectionRecordDto && null != addOrUpdateInspectionRecordDto.getInsRecordId()){
result = entInsRecordMapper.updateInspectionRecord(entInsRecord);
}else {
result = entInsRecordMapper.insert(entInsRecord);
}
if (result != 1 ){
singleResult.setCode(Code.ERROR.getCode());
singleResult.setMessage(Message.ERROR);
}
return singleResult;
}
public Object selectInspectionRecord(String inspectionRecordName,Integer page,Integer pageSize){
Page<EntInsRecord> entInsRecords = (Page<EntInsRecord>) entInsRecordMapper.selectInspectionRecord(inspectionRecordName);
return entInsRecords;
}
public Object sparePartList(String name,Integer page,Integer pageSize){
Page<SparePart>sparePartList = (Page<SparePart>) sparePartMapper.sparePartList(name);
return sparePartList;
}
public SingleResult sparePartUpdate(SparePartDto sparePartDto){
SingleResult singleResult = new SingleResult();
int result = 0;
SparePart sparePart = new SparePart();
BeanUtils.copyProperties(sparePartDto,sparePart);
if (null != sparePart && null != sparePart.getSparePartId()){
result = sparePartMapper.updateSparePart(sparePart);
}else {
result = sparePartMapper.insert(sparePart);
}
if (result != 1 ){
singleResult.setCode(Code.ERROR.getCode());
singleResult.setMessage(Message.ERROR);
}
return singleResult;
}
public SingleResult entDeviceMaintenancePlanUpdate(EntDeviceMaintenancePlanDto entDeviceMaintenancePlanDto){
SingleResult singleResult = new SingleResult();
EntDeviceMaintenancePlan entDeviceMaintenancePlan = new EntDeviceMaintenancePlan();
BeanUtils.copyProperties(entDeviceMaintenancePlanDto,entDeviceMaintenancePlan);
int result = 0;
if (null != entDeviceMaintenancePlanDto && null != entDeviceMaintenancePlan.getMaintenancePlanId()){
result = entDeviceMaintenancePlanMapper.updateEntDeviceMaintenancePlan(entDeviceMaintenancePlan);
}else {
result = entDeviceMaintenancePlanMapper.insert(entDeviceMaintenancePlan);
}
if (result != 1 ){
singleResult.setCode(Code.ERROR.getCode());
singleResult.setMessage(Message.ERROR);
}
return singleResult;
}
public Object entDeviceMaintenancePlan(Integer page,Integer pageSize){
Page<EntDeviceMaintenancePlan> list = (Page<EntDeviceMaintenancePlan>) entDeviceMaintenancePlanMapper.selectEntDeviceMaintenancePlanList();
return list;
}
public SingleResult entDeviceMaintenanceRecordUpdate(EntDeviceMaintenanceRecordDto entDeviceMaintenanceRecordDto){
SingleResult singleResult = new SingleResult();
int result = 0;
EntDeviceMaintenanceRecord entDeviceMaintenanceRecord = new EntDeviceMaintenanceRecord();
BeanUtils.copyProperties(entDeviceMaintenanceRecordDto,entDeviceMaintenanceRecord);
if (null != entDeviceMaintenanceRecordDto && null != entDeviceMaintenanceRecord.getRecordId()){
result = entDeviceMaintenanceRecordMapper.UpdateEntDeviceMaintenanceRecord(entDeviceMaintenanceRecord);
}else {
result = entDeviceMaintenanceRecordMapper.insert(entDeviceMaintenanceRecord);
}
if (result != 1 ){
singleResult.setCode(Code.ERROR.getCode());
singleResult.setMessage(Message.ERROR);
}
return singleResult;
}
@PageOperation
public Object entDeviceMaintenanceRecord(Integer page,Integer pageSize){
Page<EntDeviceMaintenanceRecord> list = (Page<EntDeviceMaintenanceRecord>) entDeviceMaintenanceRecordMapper.selectEntDeviceMaintenanceRecord();
return list;
}
public Object inspectionRecord(String startTime,String endTime,Integer page,Integer pageSize){
Page<EntInspectionRecord>inspectionRecords = (Page<EntInspectionRecord>) entInspectionRecordMapper.selectInspectionRecord(startTime,endTime);
return inspectionRecords;
}
public Object repairPlan(Integer page,Integer pageSize){
Page<EntRepairPlan>entRepairPlans = (Page<EntRepairPlan>) entRepairPlanMapper.selectRepairPlan();
return entRepairPlans;
}
public SingleResult repairPlanUpdate(EntRepairPlanDto entRepairPlanDto){
SingleResult singleResult = new SingleResult();
EntRepairPlan entRepairPlan = new EntRepairPlan();
BeanUtils.copyProperties(entRepairPlanDto,entRepairPlan);
int result = 0;
if (null != entRepairPlanDto && null != entRepairPlan.getRepairPlanId()){
result = entRepairPlanMapper.updateRepairPlan(entRepairPlan);
}else{
result = entRepairPlanMapper.insert(entRepairPlan);
}
if (result != 1 ){
singleResult.setCode(Code.ERROR.getCode());
singleResult.setMessage(Message.ERROR);
}
return singleResult;
}
public SingleResult submitInspection(InspectionRecordDto inspectionRecordDto){
SingleResult singleResult = new SingleResult();
EntInspectionRecord entInspectionRecord = new EntInspectionRecord();
BeanUtils.copyProperties(inspectionRecordDto,entInspectionRecord);
int result = 0;
if (null != inspectionRecordDto && null != entInspectionRecord.getInspectionId()){
result = entInspectionRecordMapper.updateEntInspectionRecord(entInspectionRecord);
}else {
result = entInspectionRecordMapper.insert(entInspectionRecord);
}
if (result != 1 ){
singleResult.setCode(Code.ERROR.getCode());
singleResult.setMessage(Message.ERROR);
}
return singleResult;
}
@PageOperation
public Object repairRecord(Integer page,Integer pageSize){
Page<EntRepairRecord> repairRecords = (Page<EntRepairRecord>) entRepairRecordMapper.repairRecord();
return repairRecords;
}
@PageOperation
public Object reportRecord(Integer page,Integer pageSize){
Page<EntReportRepair>reportRepairs = (Page<EntReportRepair>) entReportRepairMapper.reportRecord();
return reportRepairs;
}
public SingleResult addOrUpdateReportRecord(ReportRecordDto reportRecordDto){
SingleResult singleResult = new SingleResult();
EntReportRepair entReportRepair = new EntReportRepair();
BeanUtils.copyProperties(reportRecordDto,entReportRepair);
int result = 0;
if (null != reportRecordDto && null != entReportRepair.getReportRepairId()){
entReportRepairMapper.updateReportRecord(entReportRepair);
}else {
entReportRepairMapper.insert(entReportRepair);
}
if (result != 1 ){
singleResult.setCode(Code.ERROR.getCode());
singleResult.setMessage(Message.ERROR);
}
return singleResult;
}
@PageOperation
public Object operatingInstructions(OperatingInstructionDto operatingInstructionDto){
Page<EntOperatingInstruction> page = (Page<EntOperatingInstruction>) entOperatingInstructionMapper.selectOperatingInstructions(operatingInstructionDto.getName());
return page;
}
public SingleResult operatingInstructionsAddOrUpdate(OperatingInstructionsDto operatingInstructionsDto){
SingleResult singleResult = new SingleResult();
EntOperatingInstruction entOperatingInstruction = new EntOperatingInstruction();
BeanUtils.copyProperties(operatingInstructionsDto,entOperatingInstruction);
int result = 0;
if (null != operatingInstructionsDto && null != entOperatingInstruction.getOpInstructionId()){
result = entOperatingInstructionMapper.updateEntOperatingInstruction(entOperatingInstruction);
}else {
result = entOperatingInstructionMapper.insert(entOperatingInstruction);
}
if (result != 1 ){
singleResult.setCode(Code.ERROR.getCode());
singleResult.setMessage(Message.ERROR);
}
return singleResult;
}
public SingleResult manualAssignmentTask(AddOrUpdateEntUserPostListDto addOrUpdateEntUserPostTaskDto) throws Exception {
SingleResult singleResult = new SingleResult();
EntPostList entPostList = new EntPostList();
BeanUtils.copyProperties(addOrUpdateEntUserPostTaskDto,entPostList);
entPostList.setPostListId(RandomNumber.getUUid());
entPostList.setCreateBy(getUserId());
entPostList.setCreateTime(new Date());
int result = entPostListMapper.insert(entPostList);
if (result != 1 ){
singleResult.setCode(Code.ERROR.getCode());
singleResult.setMessage(Message.ERROR);
}
return singleResult;
}
public SingleResult inListStatistic(String enterpriseId,String listId,String keyWord,Integer page,Integer pageSize){
SingleResult singleResult = new SingleResult();
HashMap map = new HashMap();
Integer total = entPostListMapper.selectEntPostListCount(enterpriseId,listId,null);
//2代表已完成状态
Integer finishCount = entPostListMapper.selectEntPostListFinishedCount(enterpriseId,listId,2,null);
double finishPercent = Arith.div(total,finishCount) * 100;
map.put("finishPercent",finishPercent);
List<EntPostTask>tasks = entPostTaskMapper.selectEntUserPostTaskByListId(enterpriseId,listId,keyWord,page,pageSize);
map.put("list",tasks);
singleResult.setData(map);
return singleResult;
}
public SingleResult inListTypes(String enterpriseId){
SingleResult singleResult = new SingleResult();
List<InEntList>list = inEntListMapper.selectByEnterpriseId(enterpriseId);
singleResult.setData(list);
return singleResult;
}
public SingleResult entPostProcessStatistic(String enterpriseId,String listId,Integer year){
SingleResult singleResult = new SingleResult();
Integer total = entPostListMapper.selectEntPostListCount(enterpriseId,listId,year);
//2代表已完成状态
Integer finishCount = entPostListMapper.selectEntPostListFinishedCount(enterpriseId,listId,2,year);
double finishPercent = Arith.div(finishCount,total) * 100;
singleResult.setData(finishPercent);
return singleResult;
}
public SingleResult entPostListPercentStatistic(String enterpriseId,String listId,Integer year){
SingleResult singleResult = new SingleResult();
HashMap map = new HashMap();
long total = entPostTaskMapper.selectEntPostTaskTotal(enterpriseId,listId,year);
//2代表已完成状态
EntPostTaskStatistic entPostTaskStatistic = entPostTaskMapper.selectEntPostTaskByState(enterpriseId,listId,year);
double finishPercent = Arith.div(entPostTaskStatistic.getFinished(),total) * 100;
map.put("finished",finishPercent);
double unfinishedPercent = Arith.div(entPostTaskStatistic.getOvertime(),total) * 100;
map.put("unfinished",unfinishedPercent);
double haveInHand = Arith.div(entPostTaskStatistic.getHaveInHand(),total) * 100;
map.put("haveInHand",haveInHand);
singleResult.setData(map);
return singleResult;
}
/**
* 获取用户岗位id
* 如果redis不存在就查询再存放到redis
* */
private String getUserPostId() throws Exception {
String userId = getUserId();
Object object = redisUtil.get("postId:userId"+userId);
if (null == object){
EntUser entUser = entUserMapper.selectById(userId);
redisUtil.set("postId:userId"+userId,entUser.getPostId());
return entUser.getPostId();
}else {
return (String)object;
}
}
public SingleResult entListGroupByListId(String enterpriseId,String listId,String userId){
SingleResult singleResult = new SingleResult();
List<EntPostList> list = entPostListMapper.selectEntListGroupByListId(enterpriseId,listId,userId);
singleResult.setData(list);
return singleResult;
}
}