1303 lines
59 KiB
Java
1303 lines
59 KiB
Java
package com.rzyc.service;
|
||
|
||
import com.alibaba.excel.EasyExcel;
|
||
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.advice.CustomException;
|
||
import com.rzyc.config.RedisUtil;
|
||
import com.rzyc.controller.BaseController;
|
||
import com.rzyc.enums.DelState;
|
||
import com.rzyc.enums.RedisKeys;
|
||
import com.rzyc.model.*;
|
||
import com.rzyc.model.EasyExcel.EasyExcelEnterprise;
|
||
import com.rzyc.model.EasyExcel.EasyExcelInList;
|
||
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 com.rzyc.utils.easyexcel.EntEnterpriseListener;
|
||
import com.rzyc.utils.easyexcel.InListListener;
|
||
import org.apache.commons.collections.list.SynchronizedList;
|
||
import org.springframework.beans.BeanUtils;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.stereotype.Service;
|
||
import org.springframework.web.multipart.MultipartFile;
|
||
|
||
import java.io.IOException;
|
||
import java.util.*;
|
||
import java.util.concurrent.CopyOnWriteArrayList;
|
||
import java.util.concurrent.ThreadPoolExecutor;
|
||
import java.util.regex.Matcher;
|
||
import java.util.regex.Pattern;
|
||
|
||
/**
|
||
* 企业端pc业务 Service
|
||
* @author Xuwanxin
|
||
* @date 2022/9/29
|
||
* */
|
||
|
||
|
||
@Service
|
||
public class PcBusinessService extends BaseController {
|
||
|
||
private RedisUtil redisUtil;
|
||
|
||
private ThreadPoolExecutor executor;
|
||
|
||
@Autowired
|
||
public PcBusinessService(RedisUtil redisUtil,ThreadPoolExecutor executor) {
|
||
this.redisUtil = redisUtil;
|
||
this.executor = executor;
|
||
}
|
||
|
||
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());
|
||
entPostMap.put("postPath",entPost.getPostPath());
|
||
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() && (null != entUserPostTaskDto.getTaskState()&& 3 != entUserPostTaskDto.getTaskState())){
|
||
//2为正在进行中
|
||
entUserPostTaskDto.setTaskState(1);
|
||
}
|
||
//EntPostTask
|
||
List<EntPostTask>list = entPostTaskMapper.selectEntUserPostTask(entUserPostTaskDto.getEnterpriseId(),entUserPostTaskDto.getEntUserId(),entUserPostTaskDto.getPostId()
|
||
,entUserPostTaskDto.getListId(),entUserPostTaskDto.getContent(),entUserPostTaskDto.getTaskState(),entUserPostTaskDto.getPostListId());
|
||
return list;
|
||
}
|
||
|
||
public List entUserPostDuty(EntUserPostDutyDto entUserPostDutyDto) throws Exception {
|
||
entUserPostDutyDto.setPostId(getUserPostId());
|
||
//EntPostDuty
|
||
List<EntPostDuty>list = entPostDutyMapper.selectEntUserPostDuty(entUserPostDutyDto.getEnterpriseId(),entUserPostDutyDto.getPostId());
|
||
return list;
|
||
}
|
||
|
||
@PageOperation
|
||
public SingleResult entUserCredential(String enterpriseId, String entUserId,Integer page,Integer pageSize,Integer credentialState){
|
||
SingleResult singleResult = new SingleResult();
|
||
Page<EntUserCredential>list = (Page<EntUserCredential>) entUserCredentialMapper.selectEntUserCredential(enterpriseId,entUserId,credentialState);
|
||
singleResult.setDataPager(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);
|
||
EntUserCredential credential = entUserCredentialMapper.selectById(entUserCredential.getCredentialId());
|
||
if (null != credential) {
|
||
entUserCredential.setModifyBy(getUserId());
|
||
entUserCredential.setModifyTime(new Date());
|
||
result += entUserCredentialMapper.updateEntUserCredential(entUserCredential);
|
||
}else {
|
||
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;
|
||
}
|
||
|
||
@PageOperation
|
||
public SingleResult entUserList(String keyContent,Integer page,Integer pageSize,String postId,String enterpriseId,Integer userType){
|
||
SingleResult singleResult = new SingleResult();
|
||
Page<EntUser>users = (Page<EntUser>) entUserMapper.selectEntUserList(keyContent,postId,enterpriseId,userType);
|
||
//计算履职百分比,后期这里使用redis来读取履职进度
|
||
for (EntUser e:users.getResult()) {
|
||
Integer total = e.getFinishTask() + e.getOngoingTask() + e.getOverTimeTask();
|
||
if (null != total && total > 0){
|
||
double percent = Arith.div(e.getFinishTask(),total) * 100;
|
||
e.setEntUserTaskPercent(percent);
|
||
}
|
||
}
|
||
singleResult.setDataPager(users);
|
||
return singleResult;
|
||
}
|
||
|
||
public SingleResult entUserListNoPage(String name,String enterpriseId){
|
||
SingleResult singleResult = new SingleResult();
|
||
List<EntUser>users = entUserMapper.selectEntUserListNoPage(name,enterpriseId);
|
||
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;
|
||
}
|
||
if (null != addOrUpdateEntUserDto.getPostId() && addOrUpdateEntUserDto.getPostId().equals("company")){
|
||
throw new CustomException(Message.CANT_ADD_IN_COMPANY_LEVEL);
|
||
}
|
||
//验证数据重复
|
||
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.getMobile()));
|
||
int result = 0 ;
|
||
if (StringUtils.isNotBlank(entUser.getEntUserId())){
|
||
EntUser phone = entUserMapper.validMobile(entUser.getMobile(),entUser.getEntUserId());
|
||
if (null != phone){
|
||
throw new CustomException(Message.HAS_MOBILE);
|
||
}
|
||
result = entUserMapper.updateEntUser(entUser);
|
||
}else {
|
||
EntUser phone = entUserMapper.validMobile(entUser.getMobile(),null);
|
||
if (null != phone){
|
||
throw new CustomException(Message.HAS_MOBILE);
|
||
}
|
||
entUser.setEntUserId(RandomNumber.getUUid());
|
||
result = entUserMapper.insert(entUser);
|
||
}
|
||
if (result != 1){
|
||
singleResult.setCode(Code.ERROR.getCode());
|
||
singleResult.setMessage(Message.ERROR);
|
||
}
|
||
//插入证件图
|
||
if (null != addOrUpdateEntUserDto.getEntUserCredentialUpdateDtos() && addOrUpdateEntUserDto.getEntUserCredentialUpdateDtos().size() > 0 ){
|
||
for (EntUserCredentialUpdateDto d:addOrUpdateEntUserDto.getEntUserCredentialUpdateDtos()) {
|
||
d.setEntUserId(entUser.getEntUserId());
|
||
}
|
||
singleResult = this.entUserCredentialUpdate(addOrUpdateEntUserDto.getEntUserCredentialUpdateDtos());
|
||
}else {
|
||
entUserCredentialMapper.delEntUserCredential(entUser.getEntUserId());
|
||
}
|
||
//插入清单和任务
|
||
AssignmentTaskThread textThread = new AssignmentTaskThread(entUser.getEntUserId(),addOrUpdateEntUserDto.getEnterpriseId(),addOrUpdateEntUserDto.getPostId(),entPostListMapper,entPostTaskMapper,inEntListMapper,getUserId(),entUserMapper);
|
||
Thread thread=new Thread(textThread);
|
||
thread.start();
|
||
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,null);
|
||
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){
|
||
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<EntDeviceType>type = JSONArray.parseArray(JSONArray.toJSONString(jsonArray),EntDeviceType.class);
|
||
singleResult.setData(type);
|
||
//存redis
|
||
boolean insertRedisResult = redisUtil.set(redisUtil.appendSymbol(RedisKeys.DEVICE.getKey(),enterpriseId),type,0);
|
||
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("parentPath",entDeviceType.getParentPath());
|
||
entPostMap.put("parentName",entDeviceType.getParentName());
|
||
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;
|
||
}
|
||
|
||
@PageOperation
|
||
public SingleResult entEquipmentList(String enterpriseId, String typeId,Integer page,Integer pageSize,String keyWord){
|
||
SingleResult singleResult = new SingleResult();
|
||
Page<EntDevice> devices = (Page<EntDevice>) entDeviceMapper.selectEntEquipmentList(enterpriseId,typeId,keyWord);
|
||
singleResult.setDataPager(devices);
|
||
return singleResult;
|
||
}
|
||
|
||
public SingleResult deviceDetail(String deviceId){
|
||
SingleResult singleResult = new SingleResult();
|
||
EntDevice entDevice = entDeviceMapper.selectById(deviceId);
|
||
EntDeviceType entDeviceType = entDeviceTypeMapper.selectById(entDevice.getTypeId());
|
||
entDevice.setDeviceType(entDeviceType);
|
||
singleResult.setData(entDevice);
|
||
return singleResult;
|
||
}
|
||
|
||
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());
|
||
EntPost post = entPostMapper.getParentPost(addOrUpdateEntPostDto.getPostId());
|
||
if (null != post && null != post.getPostPath()){
|
||
entPost.setPostPath(post.getPostPath() + "," + addOrUpdateEntPostDto.getPostId());
|
||
}else {
|
||
entPost.setPostPath(addOrUpdateEntPostDto.getPostId());
|
||
}
|
||
result = entPostMapper.updateEntPost(entPost);
|
||
}else {
|
||
String uuid = RandomNumber.getUUid();
|
||
entPost.setPostId(uuid);
|
||
entPost.setCreateTime(new Date());
|
||
entPost.setCreateBy(getUserId());
|
||
EntPost post = entPostMapper.getParentPost(addOrUpdateEntPostDto.getParentId());
|
||
if (null != post && null != post.getPostPath()){
|
||
entPost.setPostPath(post.getPostPath() + "," + uuid);
|
||
}else {
|
||
entPost.setPostPath(uuid);
|
||
}
|
||
result = entPostMapper.insertEntPost(entPost);
|
||
}
|
||
if (result != 1 ){
|
||
singleResult.setCode(Code.ERROR.getCode());
|
||
singleResult.setMessage(Message.ERROR);
|
||
}
|
||
//更新redis
|
||
List<EntDeviceType> entDeviceTypes = entDeviceTypeMapper.selectEntEquipmentTypeList(addOrUpdateEntPostDto.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(),addOrUpdateEntPostDto.getEnterpriseId()),posts,0);
|
||
|
||
//生成岗位职责(企业全体员工都涉及的)
|
||
List<InEntList>list = inEntListMapper.selectByEnterpriseId(entPost.getEnterpriseId());
|
||
List<EntPostDuty> duties = new ArrayList<>();
|
||
for (InEntList s:list) {
|
||
EntPostDuty entPostDuty = new EntPostDuty();
|
||
entPostDuty.setDutyId(RandomNumber.getUUid());
|
||
entPostDuty.setPostId(entPost.getPostId());
|
||
entPostDuty.setDutyItem(s.getItemContent());
|
||
entPostDuty.setSortId(s.getSortId());
|
||
entPostDuty.setEnterpriseId(s.getEnterpriseId());
|
||
entPostDuty.setCreateBy(getUserId());
|
||
entPostDuty.setCreateTime(new Date());
|
||
duties.add(entPostDuty);
|
||
}
|
||
entPostDutyMapper.deleteByPostId(entPost.getPostId());
|
||
entPostDutyMapper.insertList(duties);
|
||
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);
|
||
}
|
||
//更新redis
|
||
List<EntDeviceType> entDeviceTypes = entDeviceTypeMapper.selectEntEquipmentTypeList(addOrUpdateEntEquipmentTypeDto.getEnterpriseId());
|
||
//树结构处理
|
||
JSONArray jsonArray = handleEntEquipment(entDeviceTypes);
|
||
List<EntDeviceType>types = JSONArray.parseArray(JSONArray.toJSONString(jsonArray),EntDeviceType.class);
|
||
singleResult.setData(types);
|
||
//存redis
|
||
boolean insertRedisResult = redisUtil.set(redisUtil.appendSymbol(RedisKeys.DEVICE.getKey(),addOrUpdateEntEquipmentTypeDto.getEnterpriseId()),types,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;
|
||
}
|
||
|
||
@PageOperation
|
||
public SingleResult deviceInspectionCycle(String inspectionName,String deviceId,Integer page,Integer pageSize){
|
||
SingleResult singleResult = new SingleResult();
|
||
Page<EntDeviceInsCycle>list = (Page<EntDeviceInsCycle>) entDeviceInsCycleMapper.deviceInspectionCycle(inspectionName,deviceId);
|
||
singleResult.setDataPager(list);
|
||
return singleResult;
|
||
}
|
||
|
||
public SingleResult addOrUpdateDeviceInspectionCycle(AddOrUpdateDeviceInspectionCycleDto addOrUpdateDeviceInspectionCycleDto) throws Exception {
|
||
SingleResult singleResult = new SingleResult();
|
||
EntDeviceInsCycle cycle = entDeviceInsCycleMapper.selectByDeviceId(addOrUpdateDeviceInspectionCycleDto.getDeviceId());
|
||
if (null != cycle){
|
||
singleResult.setCode(Code.ERROR.getCode());
|
||
singleResult.setMessage(Message.NOT_ONLY_INSPECTION_CYCLE);
|
||
return singleResult;
|
||
}
|
||
Integer result = 0;
|
||
EntDeviceInsCycle entDeviceInsCycle = new EntDeviceInsCycle();
|
||
BeanUtils.copyProperties(addOrUpdateDeviceInspectionCycleDto,entDeviceInsCycle);
|
||
Date nextTime = calculationDays(addOrUpdateDeviceInspectionCycleDto.getInspectionCycle());
|
||
entDeviceInsCycle.setNextTimeInspection(nextTime);
|
||
if (null != addOrUpdateDeviceInspectionCycleDto && null != addOrUpdateDeviceInspectionCycleDto.getInspectionId()){
|
||
entDeviceInsCycle.setModifyBy(getUserId());
|
||
entDeviceInsCycle.setModifyTime(new Date());
|
||
result = entDeviceInsCycleMapper.updateDeviceInspectionCycle(entDeviceInsCycle);
|
||
}else {
|
||
entDeviceInsCycle.setInspectionId(RandomNumber.getUUid());
|
||
entDeviceInsCycle.setCreateBy(getUserId());
|
||
entDeviceInsCycle.setCreateTime(new Date());
|
||
result = entDeviceInsCycleMapper.insert(entDeviceInsCycle);
|
||
}
|
||
if (result != 1 ){
|
||
singleResult.setCode(Code.ERROR.getCode());
|
||
singleResult.setMessage(Message.ERROR);
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
public SingleResult addOrUpdateInspectionRecord(AddOrUpdateInspectionRecordDto addOrUpdateInspectionRecordDto) throws Exception {
|
||
SingleResult singleResult = new SingleResult();
|
||
EntInsRecord entInsRecord = new EntInsRecord();
|
||
BeanUtils.copyProperties(addOrUpdateInspectionRecordDto,entInsRecord);
|
||
//存放设备的周期巡检id
|
||
EntDeviceInsCycle cycle = entDeviceInsCycleMapper.selectByDeviceId(addOrUpdateInspectionRecordDto.getDeviceId());
|
||
int result = 0;
|
||
if (null != addOrUpdateInspectionRecordDto && null != addOrUpdateInspectionRecordDto.getInsRecordId()){
|
||
if (cycle != null) {
|
||
entInsRecord.setCycleId(cycle.getInspectionId());
|
||
}
|
||
entInsRecord.setModifyBy(getUserId());
|
||
entInsRecord.setModifyTime(new Date());
|
||
result = entInsRecordMapper.updateInspectionRecord(entInsRecord);
|
||
}else {
|
||
if (cycle != null) {
|
||
entInsRecord.setCycleId(cycle.getInspectionId());
|
||
}
|
||
entInsRecord.setInsRecordId(RandomNumber.getUUid());
|
||
entInsRecord.setCreateBy(getUserId());
|
||
entInsRecord.setCreateTime(new Date());
|
||
result = entInsRecordMapper.insert(entInsRecord);
|
||
}
|
||
if (result != 1 ){
|
||
singleResult.setCode(Code.ERROR.getCode());
|
||
singleResult.setMessage(Message.ERROR);
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
|
||
@PageOperation
|
||
public SingleResult selectInsRecord(String deviceId,String inspectionRecordName,Integer page,Integer pageSize){
|
||
SingleResult singleResult = new SingleResult();
|
||
Page<EntInsRecord> entInsRecords = (Page<EntInsRecord>) entInsRecordMapper.selectInspectionRecord(deviceId,inspectionRecordName);
|
||
singleResult.setDataPager(entInsRecords);
|
||
return singleResult;
|
||
}
|
||
|
||
@PageOperation
|
||
public SingleResult sparePartList(String name, Integer page, Integer pageSize){
|
||
SingleResult singleResult = new SingleResult();
|
||
Page<SparePart>sparePartList = (Page<SparePart>) sparePartMapper.sparePartList(name);
|
||
singleResult.setDataPager(sparePartList);
|
||
return singleResult;
|
||
}
|
||
|
||
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 {
|
||
entDeviceMaintenancePlan.setMaintenancePlanId(RandomNumber.getUUid());
|
||
result = entDeviceMaintenancePlanMapper.insert(entDeviceMaintenancePlan);
|
||
}
|
||
if (result != 1 ){
|
||
singleResult.setCode(Code.ERROR.getCode());
|
||
singleResult.setMessage(Message.ERROR);
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
@PageOperation
|
||
public SingleResult entDeviceMaintenancePlan(String deviceId,Integer page,Integer pageSize){
|
||
SingleResult singleResult = new SingleResult();
|
||
Page<EntDeviceMaintenancePlan> list = (Page<EntDeviceMaintenancePlan>) entDeviceMaintenancePlanMapper.selectEntDeviceMaintenancePlanList(deviceId);
|
||
singleResult.setDataPager(list);
|
||
return singleResult;
|
||
}
|
||
|
||
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 {
|
||
entDeviceMaintenanceRecord.setRecordId(RandomNumber.getUUid());
|
||
result = entDeviceMaintenanceRecordMapper.insert(entDeviceMaintenanceRecord);
|
||
}
|
||
if (result != 1 ){
|
||
singleResult.setCode(Code.ERROR.getCode());
|
||
singleResult.setMessage(Message.ERROR);
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
@PageOperation
|
||
public SingleResult entDeviceMaintenanceRecord(String deviceId,Integer page,Integer pageSize){
|
||
SingleResult singleResult = new SingleResult();
|
||
Page<EntDeviceMaintenanceRecord> list = (Page<EntDeviceMaintenanceRecord>) entDeviceMaintenanceRecordMapper.selectEntDeviceMaintenanceRecord(deviceId);
|
||
singleResult.setDataPager(list);
|
||
return singleResult;
|
||
}
|
||
|
||
@PageOperation
|
||
public SingleResult inspectionRecord(String startTime,String endTime,Integer page,Integer pageSize,String deviceId){
|
||
SingleResult singleResult = new SingleResult();
|
||
Page<EntInspectionRecord>inspectionRecords = (Page<EntInspectionRecord>) entInspectionRecordMapper.selectInspectionRecord(startTime,endTime,deviceId);
|
||
singleResult.setDataPager(inspectionRecords);
|
||
return singleResult;
|
||
}
|
||
|
||
@PageOperation
|
||
public SingleResult repairPlan(Integer page,Integer pageSize,String deviceId){
|
||
SingleResult singleResult = new SingleResult();
|
||
Page<EntRepairPlan>entRepairPlans = (Page<EntRepairPlan>) entRepairPlanMapper.selectRepairPlan(deviceId);
|
||
singleResult.setDataPager(entRepairPlans);
|
||
return singleResult;
|
||
}
|
||
|
||
public SingleResult repairPlanUpdate(EntRepairPlanDto entRepairPlanDto) throws Exception {
|
||
SingleResult singleResult = new SingleResult();
|
||
EntRepairPlan entRepairPlan = new EntRepairPlan();
|
||
BeanUtils.copyProperties(entRepairPlanDto,entRepairPlan);
|
||
int result = 0;
|
||
if (null != entRepairPlanDto && null != entRepairPlan.getRepairPlanId()){
|
||
entRepairPlan.setModifyBy(getUserId());
|
||
entRepairPlan.setModifyTime(new Date());
|
||
result = entRepairPlanMapper.updateRepairPlan(entRepairPlan);
|
||
}else{
|
||
entRepairPlan.setRepairPlanId(RandomNumber.getUUid());
|
||
entRepairPlan.setCreateBy(getUserId());
|
||
entRepairPlan.setCreateTime(new Date());
|
||
result = entRepairPlanMapper.insert(entRepairPlan);
|
||
}
|
||
if (result != 1 ){
|
||
singleResult.setCode(Code.ERROR.getCode());
|
||
singleResult.setMessage(Message.ERROR);
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
public SingleResult submitInspection(InspectionRecordDto inspectionRecordDto) throws Exception {
|
||
SingleResult singleResult = new SingleResult();
|
||
EntInspectionRecord entInspectionRecord = new EntInspectionRecord();
|
||
BeanUtils.copyProperties(inspectionRecordDto,entInspectionRecord);
|
||
int result = 0;
|
||
if (null != inspectionRecordDto && null != entInspectionRecord.getInspectionId()){
|
||
entInspectionRecord.setModifyBy(getUserId());
|
||
entInspectionRecord.setModifyTime(new Date());
|
||
result = entInspectionRecordMapper.updateEntInspectionRecord(entInspectionRecord);
|
||
}else {
|
||
entInspectionRecord.setInspectionId(RandomNumber.getUUid());
|
||
entInspectionRecord.setCreateBy(getUserId());
|
||
entInspectionRecord.setCreateTime(new Date());
|
||
//state 1 是待检测
|
||
entInspectionRecord.setInspectionState(1);
|
||
result = entInspectionRecordMapper.insert(entInspectionRecord);
|
||
}
|
||
if (result != 1 ){
|
||
singleResult.setCode(Code.ERROR.getCode());
|
||
singleResult.setMessage(Message.ERROR);
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
@PageOperation
|
||
public SingleResult repairRecord(Integer page,Integer pageSize,String deviceId){
|
||
SingleResult singleResult = new SingleResult();
|
||
Page<EntRepairRecord> repairRecords = (Page<EntRepairRecord>) entRepairRecordMapper.repairRecord(deviceId);
|
||
singleResult.setDataPager(repairRecords);
|
||
return singleResult;
|
||
}
|
||
|
||
@PageOperation
|
||
public SingleResult reportRecord(Integer page,Integer pageSize,String deviceId){
|
||
SingleResult singleResult = new SingleResult();
|
||
Page<EntReportRepair>reportRepairs = (Page<EntReportRepair>) entReportRepairMapper.reportRecord(deviceId);
|
||
singleResult.setDataPager(reportRepairs);
|
||
return singleResult;
|
||
}
|
||
|
||
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()){
|
||
result = entReportRepairMapper.updateReportRecord(entReportRepair);
|
||
}else {
|
||
result = entReportRepairMapper.insert(entReportRepair);
|
||
}
|
||
if (result != 1 ){
|
||
singleResult.setCode(Code.ERROR.getCode());
|
||
singleResult.setMessage(Message.ERROR);
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
@PageOperation
|
||
public SingleResult operatingInstructions(String name,String deviceId,Integer page,Integer pageSize){
|
||
SingleResult SingleResult = new SingleResult();
|
||
Page<EntOperatingInstruction> p = (Page<EntOperatingInstruction>) entOperatingInstructionMapper.selectOperatingInstructions(name,deviceId);
|
||
SingleResult.setDataPager(p);
|
||
return SingleResult;
|
||
}
|
||
|
||
|
||
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 {
|
||
entOperatingInstruction.setOpInstructionId(RandomNumber.getUUid());
|
||
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 {
|
||
return insertListAndTask(addOrUpdateEntUserPostTaskDto);
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
private SingleResult insertListAndTask(AddOrUpdateEntUserPostListDto addOrUpdateEntUserPostTaskDto) throws Exception {
|
||
EntPostList entPostList = new EntPostList();
|
||
SingleResult singleResult = new SingleResult();
|
||
BeanUtils.copyProperties(addOrUpdateEntUserPostTaskDto,entPostList);
|
||
entPostList.setCreateBy(getUserId());
|
||
entPostList.setCreateTime(new Date());
|
||
entPostList.setDelState(DelState.NOT_DEL.getState());
|
||
entPostList.setPostListId(RandomNumber.getUUid());
|
||
int result = entPostListMapper.insert(entPostList);
|
||
if (result != 1 ){
|
||
singleResult.setCode(Code.ERROR.getCode());
|
||
singleResult.setMessage(Message.ERROR);
|
||
}
|
||
//插入任务
|
||
this.addFactorTask(entPostList,getUserId());
|
||
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(finishCount,total) * 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);
|
||
if (null != finishCount && finishCount >= 0 ){
|
||
double finishPercent = Arith.div(finishCount,total) * 100;
|
||
singleResult.setData(finishPercent);
|
||
}
|
||
|
||
return singleResult;
|
||
}
|
||
|
||
|
||
|
||
public SingleResult entPostListPercentStatistic(String enterpriseId,String listId,Integer year)throws Exception{
|
||
SingleResult singleResult = new SingleResult();
|
||
HashMap map = new HashMap();
|
||
long total = entPostTaskMapper.selectEntPostTaskTotal(enterpriseId,listId,year);
|
||
//2代表已完成状态
|
||
EntPostTaskStatistic entPostTaskStatistic = entPostTaskMapper.selectEntPostTaskByState(enterpriseId,listId,year);
|
||
if (null != entPostTaskStatistic){
|
||
double finishPercent = Arith.div(entPostTaskStatistic.getFinished(),total) * 100;
|
||
finishPercent = TypeConversion.decimalFormat(finishPercent,2);
|
||
map.put("finished",finishPercent);
|
||
double unfinishedPercent = Arith.div(entPostTaskStatistic.getOvertime(),total) * 100;
|
||
unfinishedPercent = TypeConversion.decimalFormat(unfinishedPercent,2);
|
||
map.put("unfinished",unfinishedPercent);
|
||
double haveInHand = Arith.div(entPostTaskStatistic.getHaveInHand(),total) * 100;
|
||
haveInHand = TypeConversion.decimalFormat(haveInHand,2);
|
||
map.put("haveInHand",haveInHand);
|
||
//数量
|
||
map.put("finishNumber",entPostTaskStatistic.getFinished());
|
||
map.put("unFinishNumber",entPostTaskStatistic.getOvertime());
|
||
map.put("haveInHandNumber",entPostTaskStatistic.getHaveInHand());
|
||
singleResult.setData(map);
|
||
}else {
|
||
map.put("finished",0);
|
||
map.put("unfinished",0);
|
||
map.put("haveInHand",0);
|
||
singleResult.setData(map);
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
|
||
/**
|
||
* 获取用户岗位id
|
||
* 如果redis不存在,就查询再存放到redis
|
||
* */
|
||
private String getUserPostId() throws Exception {
|
||
String userId = getUserId();
|
||
if (StringUtils.isNotBlank(userId)){
|
||
Object object = redisUtil.get(redisUtil.appendSymbol(RedisKeys.POSTID.getKey(),RedisKeys.USERID.getKey())+userId);
|
||
if (null == object){
|
||
EntUser entUser = entUserMapper.selectById(userId);
|
||
redisUtil.set(redisUtil.appendSymbol(RedisKeys.POSTID.getKey(),RedisKeys.USERID.getKey())+userId,entUser.getPostId());
|
||
return entUser.getPostId();
|
||
}else {
|
||
return (String)object;
|
||
}
|
||
}
|
||
return null;
|
||
}
|
||
|
||
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;
|
||
}
|
||
|
||
public SingleResult entUserTypeList(){
|
||
SingleResult singleResult = new SingleResult();
|
||
List<EntUserType>list = entUserTypeMapper.selectEntUserType();
|
||
singleResult.setData(list);
|
||
return singleResult;
|
||
}
|
||
|
||
@PageOperation
|
||
public SingleResult entEmEquipmentList(String enterpriseId,Integer page,Integer pageSize,String resourceType){
|
||
SingleResult singleResult = new SingleResult();
|
||
Page<EntEmEquipment> entEmEquipments = (Page<EntEmEquipment>) entEmEquipmentMapper.selectEntEmEquipmentList(enterpriseId,resourceType);
|
||
singleResult.setDataPager(entEmEquipments);
|
||
return singleResult;
|
||
}
|
||
|
||
public SingleResult entEmEquipmentUpdate(EntEmEquipmentDto entEmEquipmentDto) throws Exception {
|
||
SingleResult singleResult = new SingleResult();
|
||
EntEmEquipment entEmEquipment = new EntEmEquipment();
|
||
BeanUtils.copyProperties(entEmEquipmentDto,entEmEquipment);
|
||
if(null != entEmEquipment.getEntEmEquipmentId() ){
|
||
entEmEquipment.setModifyBy(getUserId());
|
||
entEmEquipment.setModifyTime(new Date());
|
||
entEmEquipmentMapper.updateEntEmEquipment(entEmEquipment);
|
||
}else {
|
||
entEmEquipment.setCreateBy(getUserId());
|
||
entEmEquipment.setCreateTime(new Date());
|
||
entEmEquipment.setEntEmEquipmentId(RandomNumber.getUUid());
|
||
entEmEquipmentMapper.insert(entEmEquipment);
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
@PageOperation
|
||
public SingleResult entEmExpertList(String enterpriseId,Integer page,Integer pageSize,String entEmExpertClass,String entEmExpertCategory,String name){
|
||
SingleResult singleResult = new SingleResult();
|
||
Page<EntEmExpert>list = (Page<EntEmExpert>)entEmExpertMapper.selectEntEmExpertList(enterpriseId,entEmExpertClass,entEmExpertCategory,name);
|
||
singleResult.setDataPager(list);
|
||
return singleResult;
|
||
}
|
||
|
||
public SingleResult entEmExpertUpdate(EntEmExpertDto entEmExpertDto) throws Exception {
|
||
SingleResult singleResult = new SingleResult();
|
||
EntEmExpert entEmExpert = new EntEmExpert();
|
||
BeanUtils.copyProperties(entEmExpertDto,entEmExpert);
|
||
if(null != entEmExpert.getEntEmExpertId()){
|
||
entEmExpert.setModifyBy(getUserId());
|
||
entEmExpert.setModifyTime(new Date());
|
||
entEmExpertMapper.updateEntEmExpertUpdate(entEmExpert);
|
||
}else {
|
||
entEmExpert.setCreateBy(getUserId());
|
||
entEmExpert.setCreateTime(new Date());
|
||
entEmExpert.setEntEmExpertId(RandomNumber.getUUid());
|
||
entEmExpertMapper.insert(entEmExpert);
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
@PageOperation
|
||
public SingleResult entEmReservePlanList(String enterpriseId,Integer page,Integer pageSize,String entEmReservePlanName){
|
||
SingleResult singleResult = new SingleResult();
|
||
Page<EntEmReservePlan>list = (Page<EntEmReservePlan>) entEmReservePlanMapper.selectEntEmReservePlanList(enterpriseId,entEmReservePlanName);
|
||
singleResult.setDataPager(list);
|
||
return singleResult;
|
||
}
|
||
|
||
public SingleResult entEmReservePlanUpdate(EntEmReservePlanDto entEmReservePlanDto) throws Exception {
|
||
SingleResult singleResult = new SingleResult();
|
||
EntEmReservePlan entEmReservePlan = new EntEmReservePlan();
|
||
BeanUtils.copyProperties(entEmReservePlanDto,entEmReservePlan);
|
||
EntEmReservePlan reservePlan = entEmReservePlanMapper.selectById(entEmReservePlan.getEntEmReservePlanId());
|
||
if(null != reservePlan && null != reservePlan.getEntEmReservePlanId()){
|
||
entEmReservePlan.setModifyBy(getUserId());
|
||
entEmReservePlan.setModifyTime(new Date());
|
||
entEmReservePlanMapper.updateEntEmReservePlan(entEmReservePlan);
|
||
}else {
|
||
entEmReservePlan.setCreateBy(getUserId());
|
||
entEmReservePlan.setCreateTime(new Date());
|
||
entEmReservePlanMapper.insert(entEmReservePlan);
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
@PageOperation
|
||
public SingleResult entEmRehearsalList(String enterpriseId,Integer page,Integer pageSize,String entEmRehearsalProject) throws Exception{
|
||
SingleResult singleResult = new SingleResult();
|
||
Page<EntEmRehearsal>entEmRehearsals = (Page<EntEmRehearsal>) entEmRehearsalMapper.selectEntEmRehearsalList(enterpriseId,entEmRehearsalProject);
|
||
singleResult.setDataPager(entEmRehearsals);
|
||
return singleResult;
|
||
}
|
||
|
||
|
||
public SingleResult entEmRehearsalUpdate(EntEmRehearsalDto entEmRehearsalDto) throws Exception {
|
||
SingleResult singleResult = new SingleResult();
|
||
EntEmRehearsal entEmRehearsal = new EntEmRehearsal();
|
||
BeanUtils.copyProperties(entEmRehearsalDto,entEmRehearsal);
|
||
EntEmRehearsal emRehearsal = entEmRehearsalMapper.selectById(entEmRehearsal.getEntEmRehearsalId());
|
||
if(null != emRehearsal && null != emRehearsal.getEntEmRehearsalId()){
|
||
entEmRehearsal.setModifyBy(getUserId());
|
||
entEmRehearsal.setModifyTime(new Date());
|
||
entEmRehearsalMapper.updateEntEmRehearsal(entEmRehearsal);
|
||
}else {
|
||
entEmRehearsal.setCreateBy(getUserId());
|
||
entEmRehearsal.setCreateTime(new Date());
|
||
entEmRehearsalMapper.insert(entEmRehearsal);
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
public SingleResult entEmRehearsalDelete(String id)throws Exception{
|
||
SingleResult singleResult = new SingleResult();
|
||
int result = entEmRehearsalMapper.updateDelState(id);
|
||
if (result != 1){
|
||
singleResult.setCode(Code.ERROR.getCode());
|
||
singleResult.setMessage(Message.ERROR);
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
public SingleResult entEmReservePlanDelete(String id)throws Exception{
|
||
SingleResult singleResult = new SingleResult();
|
||
int result = entEmReservePlanMapper.updateDelState(id);
|
||
if (result != 1){
|
||
singleResult.setCode(Code.ERROR.getCode());
|
||
singleResult.setMessage(Message.ERROR);
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
|
||
public SingleResult entEmExpertDelete(String id){
|
||
SingleResult singleResult = new SingleResult();
|
||
int result = entEmExpertMapper.updateDelState(id);
|
||
if (result != 1){
|
||
singleResult.setCode(Code.ERROR.getCode());
|
||
singleResult.setMessage(Message.ERROR);
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
|
||
public SingleResult entEmEquipmentDelete(String id){
|
||
SingleResult singleResult = new SingleResult();
|
||
int result = entEmEquipmentMapper.updateDelState(id);
|
||
if (result != 1){
|
||
singleResult.setCode(Code.ERROR.getCode());
|
||
singleResult.setMessage(Message.ERROR);
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
//向后加时间
|
||
private Date calculationDays(Integer day){
|
||
Calendar cal = Calendar.getInstance();
|
||
int amount = day;
|
||
cal.add(Calendar.DATE, amount);
|
||
Date date = cal.getTime();
|
||
return date;
|
||
}
|
||
|
||
public SingleResult selectEntEquipmentOverdue(String enterpriseId,Integer state ,Integer deviceName){
|
||
SingleResult singleResult = new SingleResult();
|
||
List<EntDevice>devices = entDeviceMapper.selectEntEquipmentOverdue(enterpriseId);
|
||
singleResult.setData(devices);
|
||
return singleResult;
|
||
}
|
||
|
||
public SingleResult repairRecordUpdate(EntRepairRecordDto entRepairRecordDto) throws Exception {
|
||
SingleResult singleResult = new SingleResult();
|
||
EntRepairRecord entRepairRecord = new EntRepairRecord();
|
||
BeanUtils.copyProperties(entRepairRecordDto,entRepairRecord);
|
||
int result = 0;
|
||
if (null != entRepairRecordDto && null != entRepairRecordDto.getRepairRecordId()){
|
||
entRepairRecord.setModifyBy(getUserId());
|
||
entRepairRecord.setModifyTime(new Date());
|
||
result =entRepairRecordMapper.repairRecordUpdate(entRepairRecord);
|
||
}else {
|
||
entRepairRecord.setCreateBy(getUserId());
|
||
entRepairRecord.setCreateTime(new Date());
|
||
result = entRepairRecordMapper.insert(entRepairRecord);
|
||
}
|
||
if (result <= 0){
|
||
singleResult.setCode(Code.ERROR.getCode());
|
||
singleResult.setMessage(Message.ERROR);
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
public SingleResult entDeviceDelete(String deviceId){
|
||
SingleResult singleResult = new SingleResult();
|
||
int result = entDeviceMapper.updateDelState(deviceId);
|
||
if (result <= 0){
|
||
singleResult.setCode(Code.ERROR.getCode());
|
||
singleResult.setMessage(Message.ERROR);
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
public SingleResult deviceInspectionCycleDelete(String deviceInspectionCycleId){
|
||
SingleResult singleResult = new SingleResult();
|
||
int result = entDeviceInsCycleMapper.updateDelState(deviceInspectionCycleId);
|
||
if (result <= 0){
|
||
singleResult.setCode(Code.ERROR.getCode());
|
||
singleResult.setMessage(Message.ERROR);
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
public SingleResult deviceEntInsRecordDelete(String deviceEntInsRecordId){
|
||
SingleResult singleResult = new SingleResult();
|
||
int result = entInsRecordMapper.updateDelState(deviceEntInsRecordId);
|
||
if (result <= 0){
|
||
singleResult.setCode(Code.ERROR.getCode());
|
||
singleResult.setMessage(Message.ERROR);
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
public SingleResult entDeviceMaintenancePlanDelete(String deviceEntInsPlanId){
|
||
SingleResult singleResult = new SingleResult();
|
||
int result = entDeviceMaintenancePlanMapper.updateDelState(deviceEntInsPlanId);
|
||
if (result <= 0){
|
||
singleResult.setCode(Code.ERROR.getCode());
|
||
singleResult.setMessage(Message.ERROR);
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
|
||
public SingleResult entDeviceMaintenanceRecordDelete(String deviceEntInsRecordId){
|
||
SingleResult singleResult = new SingleResult();
|
||
int result = entDeviceMaintenanceRecordMapper.updateDelState(deviceEntInsRecordId);
|
||
if (result <= 0){
|
||
singleResult.setCode(Code.ERROR.getCode());
|
||
singleResult.setMessage(Message.ERROR);
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
public SingleResult entDeviceEntInspectionRecordDelete(String deviceEntInspectionRecordId){
|
||
SingleResult singleResult = new SingleResult();
|
||
int result = entInspectionRecordMapper.updateDelState(deviceEntInspectionRecordId);
|
||
if (result <= 0){
|
||
singleResult.setCode(Code.ERROR.getCode());
|
||
singleResult.setMessage(Message.ERROR);
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
public SingleResult entDeviceRepairPlanDelete(String repairPlanId){
|
||
SingleResult singleResult = new SingleResult();
|
||
int result = entRepairPlanMapper.updateDelState(repairPlanId);
|
||
if (result <= 0){
|
||
singleResult.setCode(Code.ERROR.getCode());
|
||
singleResult.setMessage(Message.ERROR);
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
public SingleResult entDeviceRepairRecordDelete(String repairRecordId){
|
||
SingleResult singleResult = new SingleResult();
|
||
int result = entRepairRecordMapper.updateDelState(repairRecordId);
|
||
if (result <= 0){
|
||
singleResult.setCode(Code.ERROR.getCode());
|
||
singleResult.setMessage(Message.ERROR);
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
public SingleResult entDeviceReportRepairDelete(String reportRepair){
|
||
SingleResult singleResult = new SingleResult();
|
||
int result = entReportRepairMapper.updateDelState(reportRepair);
|
||
if (result <= 0){
|
||
singleResult.setCode(Code.ERROR.getCode());
|
||
singleResult.setMessage(Message.ERROR);
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
@PageOperation
|
||
public SingleResult notices(String type,Integer page,Integer pageSize) throws Exception {
|
||
SingleResult singleResult = new SingleResult();
|
||
String userId = getUserId();
|
||
List<Notice>notices = noticeMapper.selectNotices(type,userId);
|
||
singleResult.setData(notices);
|
||
return singleResult;
|
||
}
|
||
|
||
public SingleResult entNoticeNumber() throws Exception {
|
||
SingleResult singleResult = new SingleResult();
|
||
String userId = getUserId();
|
||
Notice notice = noticeMapper.selectEntNoticeNumber(userId);
|
||
singleResult.setData(notice);
|
||
return singleResult;
|
||
}
|
||
|
||
public SingleResult delStateOperatingInstruction(String opInstructionId){
|
||
SingleResult singleResult = new SingleResult();
|
||
int result = entOperatingInstructionMapper.updateStateOperatingInstruction(opInstructionId);
|
||
if (result <= 0){
|
||
singleResult.setCode(Code.ERROR.getCode());
|
||
singleResult.setMessage(Message.ERROR);
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
|
||
public SingleResult oneButtonRead() throws Exception {
|
||
SingleResult singleResult = new SingleResult();
|
||
int result = noticeMapper.oneButtonRead(getUserId());
|
||
if (result <= 0){
|
||
singleResult.setCode(Code.ERROR.getCode());
|
||
singleResult.setMessage(Message.ERROR);
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
public SingleResult manualAddListDetail(EntPostListDetailDto entPostListDetailDto){
|
||
SingleResult singleResult = new SingleResult();
|
||
EntPostListDetail entPostListDetail = new EntPostListDetail();
|
||
BeanUtils.copyProperties(entPostListDetailDto,entPostListDetail);
|
||
int result = entPostListDetailMapper.insert(entPostListDetail);
|
||
if (result <= 0){
|
||
singleResult.setCode(Code.ERROR.getCode());
|
||
singleResult.setMessage(Message.ERROR);
|
||
}
|
||
//判断任务是否完成,完成则修改为完成状态
|
||
if (null != entPostListDetailDto.getEntPostTaskId()){
|
||
EntPostTask entPostTask = entPostTaskMapper.verifyCompletion(entPostListDetailDto.getEntPostTaskId());
|
||
if (entPostTask.getNumberOfDutyPerformance().equals(entPostTask.getFrequency())){
|
||
entPostTaskMapper.updateTaskState(entPostListDetailDto.getEntPostTaskId());
|
||
}
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
@PageOperation
|
||
public SingleResult selectPostListDetail(String postListId,String userId,Integer page,Integer pageSize){
|
||
SingleResult singleResult = new SingleResult();
|
||
List<EntPostListDetail> list = entPostListDetailMapper.selectListDetail(postListId,userId);
|
||
singleResult.setData(list);
|
||
return singleResult;
|
||
}
|
||
|
||
public SingleResult repeatedRead(MultipartFile file) throws IOException {
|
||
SingleResult singleResult = new SingleResult();
|
||
EasyExcel.read(file.getInputStream(), EasyExcelInList.class, new InListListener(inListMapper,inListItemMapper,baseInClassMapper)).doReadAll();
|
||
return singleResult;
|
||
}
|
||
|
||
public SingleResult readEasyExcelOfEnterprise(MultipartFile file)throws IOException{
|
||
SingleResult singleResult = new SingleResult();
|
||
EasyExcel.read(file.getInputStream(), EasyExcelEnterprise.class, new EntEnterpriseListener(sysEnterpriseMapper,baseInClassMapper,sysOrgMapper)).doReadAll();
|
||
return singleResult;
|
||
}
|
||
|
||
public SingleResult generateLegalPersonPostAndUser()throws Exception{
|
||
SingleResult singleResult = new SingleResult();
|
||
List<SysEnterprise>sysEnterprises = sysEnterpriseMapper.selectNoLegalPersonPost();
|
||
CopyOnWriteArrayList copyOnWriteArrayList = new CopyOnWriteArrayList();
|
||
for (SysEnterprise s:sysEnterprises) {
|
||
//创建或者修改企业用户
|
||
String userId = RandomNumber.getUUid();
|
||
String postId = RandomNumber.getUUid();
|
||
|
||
SaveEntPostAndUserThread SaveEntPostAndUserThread = new SaveEntPostAndUserThread(s.getSysenterpriseid(),getUserId(),entPostMapper,entUserMapper,constantsConfigure,s.getLegalrepre(),
|
||
s.getLrlinktel(),s.getEntname(),copyOnWriteArrayList,postId,userId);
|
||
executor.execute(SaveEntPostAndUserThread);
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
public SingleResult generatePostListAndListTask()throws Exception{
|
||
SingleResult singleResult = new SingleResult();
|
||
List<EntUser>selectNoEntPostListUser = entUserMapper.selectNoEntPostListUser();
|
||
for (EntUser e:selectNoEntPostListUser) {
|
||
AssignmentTaskThread assignmentTaskThread = new AssignmentTaskThread(e.getEntUserId(),e.getEnterpriseId(),e.getPostId(),entPostListMapper,entPostTaskMapper,inEntListMapper,getUserId(),entUserMapper);
|
||
executor.execute(assignmentTaskThread);
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
public SingleResult generatePostDuty(){
|
||
SingleResult singleResult = new SingleResult();
|
||
List<EntPost>posts = entPostMapper.selectNoDutyPost();
|
||
EntPostDutyThread entPostDutyThread = new EntPostDutyThread(inEntListMapper,entPostDutyMapper,posts);
|
||
executor.execute(entPostDutyThread);
|
||
return singleResult;
|
||
}
|
||
|
||
public SingleResult addOrUpdateEntPostDuty(EntUserPostDutyDto duty) throws Exception {
|
||
EntPostDuty entPostDuty = new EntPostDuty();
|
||
BeanUtils.copyProperties(duty,entPostDuty);
|
||
SingleResult singleResult = new SingleResult();
|
||
int result = 0;
|
||
if (null == duty){
|
||
entPostDuty.setCreateTime(new Date());
|
||
entPostDuty.setCreateBy(getUserId());
|
||
result = entPostDutyMapper.insert(entPostDuty);
|
||
}else {
|
||
entPostDuty.setModifyBy(getUserId());
|
||
entPostDuty.setModifyTime(new Date());
|
||
result = entPostDutyMapper.updatePostDuty(entPostDuty);
|
||
}
|
||
if (result <= 0){
|
||
singleResult.setCode(Code.ERROR.getCode());
|
||
singleResult.setMessage(Message.ERROR);
|
||
}
|
||
return singleResult;
|
||
}
|
||
|
||
}
|