| package doumeemes.service.business.impl; | 
|   | 
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
| import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
| import com.github.pagehelper.PageHelper; | 
| import com.github.pagehelper.PageInfo; | 
| import doumeemes.core.constants.ResponseStatus; | 
| import doumeemes.core.exception.BusinessException; | 
| import doumeemes.core.model.LoginUserInfo; | 
| import doumeemes.core.model.PageData; | 
| import doumeemes.core.model.PageWrap; | 
| import doumeemes.core.utils.Constants; | 
| import doumeemes.core.utils.DateUtil; | 
| import doumeemes.core.utils.redis.RedisUtil; | 
| import doumeemes.dao.business.ApplianceChangeDetialMapper; | 
| import doumeemes.dao.business.ApplianceChangeMapper; | 
| import doumeemes.dao.business.model.ApplianceChange; | 
| import doumeemes.dao.business.model.ApplianceChangeDetial; | 
| import doumeemes.dao.ext.dto.QueryApplianceChangeDetailExtDTO; | 
| import doumeemes.dao.ext.dto.QueryApplianceChangeExtDTO; | 
| import doumeemes.dao.ext.vo.ApplianceChangeDetailExtListVO; | 
| import doumeemes.dao.ext.vo.ApplianceChangeExtListVO; | 
| import doumeemes.service.business.ApplianceChangeService; | 
| import org.apache.commons.lang3.StringUtils; | 
| import org.apache.shiro.SecurityUtils; | 
| import org.springframework.beans.factory.annotation.Autowired; | 
| import org.springframework.data.redis.core.RedisTemplate; | 
| import org.springframework.stereotype.Service; | 
| import org.springframework.util.CollectionUtils; | 
|   | 
| import java.util.Date; | 
| import java.util.List; | 
|   | 
| /** | 
|  * 设置类-工装器具更换记录表Service实现 | 
|  * @author 江蹄蹄 | 
|  * @date 2022/07/19 14:29 | 
|  */ | 
| @Service | 
| public class ApplianceChangeServiceImpl implements ApplianceChangeService { | 
|   | 
|     @Autowired | 
|     private ApplianceChangeMapper applianceChangeMapper; | 
|   | 
|     @Autowired | 
|     private RedisTemplate<String, Object> redisTemplate; | 
|     @Autowired | 
|     private ApplianceChangeDetialServiceImpl applianceChangeDetialServiceimpl; | 
|     @Autowired | 
|     private AppliancesServiceImpl appliancesServiceimpl; | 
|   | 
|   | 
|     @Autowired | 
|     private ApplianceChangeDetialMapper applianceChangeDetialMapper; | 
|   | 
|     @Override | 
|     public Integer create(ApplianceChange applianceChange) { | 
|         applianceChangeMapper.insert(applianceChange); | 
|         return applianceChange.getId(); | 
|     } | 
|   | 
|     @Override | 
|     public void deleteById(Integer id) { | 
|         applianceChangeMapper.deleteById(id); | 
|     } | 
|   | 
|     @Override | 
|     public void delete(ApplianceChange applianceChange) { | 
|         UpdateWrapper<ApplianceChange> deleteWrapper = new UpdateWrapper<>(applianceChange); | 
|         applianceChangeMapper.delete(deleteWrapper); | 
|     } | 
|   | 
|     @Override | 
|     public void deleteByIdInBatch(List<Integer> ids) { | 
|         if (CollectionUtils.isEmpty(ids)) { | 
|             return; | 
|         } | 
|         LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|         for (Integer id: ids) { | 
|   | 
|             ApplianceChange applianceChange =applianceChangeMapper.selectById(id); | 
|             applianceChange.setDeleted(Constants.ONE); | 
|             applianceChange.setUpdateTime(new Date()); | 
|             applianceChange.setUpdateUser(user.getId()); | 
|             this.updateById(applianceChange); | 
|   | 
|             ApplianceChangeDetial applianceChangeDetial =new ApplianceChangeDetial(); | 
|             applianceChangeDetial.setDeleted(Constants.ONE); | 
|             applianceChangeDetial.setUpdateTime(new Date()); | 
|             applianceChangeDetial.setUpdateUser(user.getId()); | 
|             applianceChangeDetial.setChaneId(applianceChange.getId()); | 
|             applianceChangeDetialServiceimpl.updateBycondition(applianceChangeDetial); | 
|         } | 
|         //applianceChangeMapper.deleteBatchIds(ids); | 
|     } | 
|   | 
|     @Override | 
|     public void updateById(ApplianceChange applianceChange) { | 
|         applianceChangeMapper.updateById(applianceChange); | 
|     } | 
|   | 
|     @Override | 
|     public void updateByIdInBatch(List<ApplianceChange> applianceChanges) { | 
|         if (CollectionUtils.isEmpty(applianceChanges)) { | 
|             return; | 
|         } | 
|         for (ApplianceChange applianceChange: applianceChanges) { | 
|             this.updateById(applianceChange); | 
|         } | 
|     } | 
|   | 
|     @Override | 
|     public ApplianceChange findById(Integer id) { | 
|         return applianceChangeMapper.selectById(id); | 
|     } | 
|   | 
|     @Override | 
|     public ApplianceChange findOne(ApplianceChange applianceChange) { | 
|         QueryWrapper<ApplianceChange> wrapper = new QueryWrapper<>(applianceChange); | 
|         return applianceChangeMapper.selectOne(wrapper); | 
|     } | 
|   | 
|     @Override | 
|     public List<ApplianceChange> findList(ApplianceChange applianceChange) { | 
|         QueryWrapper<ApplianceChange> wrapper = new QueryWrapper<>(applianceChange); | 
|         return applianceChangeMapper.selectList(wrapper); | 
|     } | 
|    | 
|     @Override | 
|     public PageData<ApplianceChange> findPage(PageWrap<ApplianceChange> pageWrap) { | 
|         LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|         if(!Constants.equalsInteger(user.getType(),Constants.USERTYPE.COM)){ | 
|             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,您无权限进行该操作!"); | 
|         } | 
|         //只能查看当前根组织的数据 | 
|         pageWrap.getModel().setDeleted(Constants.ZERO); | 
|         pageWrap.getModel().setRootDepartId(user.getRootDepartment().getId()); | 
| //        if(!Constants.equalsInteger(user.getCurComDepartment().getId(),user.getRootDepartment().getId())){ | 
|         //如果当前选择的公司级组织非根组织信息,只能查看当前选择公司级组织数据 | 
|         pageWrap.getModel().setDepartId(user.getCurComDepartment().getId()); | 
| //        } | 
|         //数据权限 | 
|      /*   List<Integer> dataPermission = user.getDepartPermissionList(); | 
|         if(dataPermission!=null){ | 
|             if(dataPermission.size() == 0){ | 
|                 //只能看自己的 | 
|               //  pageWrap.getModel().setPmodelUserId(user.getId()); | 
|             }else{ | 
|                 //否则走数据权限 | 
|                 pageWrap.getModel().setDepartIds(dataPermission); | 
|             } | 
|         }*/ | 
|         PageHelper.startPage(pageWrap.getPage(), pageWrap.getCapacity()); | 
|         List<ApplianceChange> result = null;//applianceChangeMapper.selectList(pageWrap.getModel()); | 
|   | 
|         return PageData.from(new PageInfo<>(result)); | 
|     } | 
|   | 
|   | 
|     @Override | 
|     public PageData<ApplianceChangeExtListVO> findListPage(PageWrap<QueryApplianceChangeExtDTO> pageWrap) { | 
|         LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); | 
|         if(!Constants.equalsInteger(user.getType(),Constants.USERTYPE.COM)){ | 
|             throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(), "对不起,您无权限进行该操作!"); | 
|         } | 
|         //只能查看当前根组织的数据 | 
|         pageWrap.getModel().setDeleted(Constants.ZERO); | 
|         pageWrap.getModel().setRootDepartId(user.getRootDepartment().getId()); | 
| //        if(!Constants.equalsInteger(user.getCurComDepartment().getId(),user.getRootDepartment().getId())){ | 
|         //如果当前选择的公司级组织非根组织信息,只能查看当前选择公司级组织数据 | 
|         pageWrap.getModel().setDepartId(user.getCurComDepartment().getId()); | 
| //        } | 
|         //数据权限 | 
|         List<Integer> dataPermission = user.getDepartPermissionList(); | 
|         if(dataPermission!=null){ | 
|             pageWrap.getModel().setCreateUser(user.getId()); | 
|             pageWrap.getModel().setDepartIds(dataPermission); | 
|         /*    if(dataPermission.size() == 0){ | 
|                 //只能看自己的 | 
|               //  pageWrap.getModel().setPmodelUserId(user.getId()); | 
|   | 
|             }else{ | 
|                 //否则走数据权限 | 
|   | 
|             }*/ | 
|         } | 
|         PageHelper.startPage(pageWrap.getPage(), pageWrap.getCapacity()); | 
|         List<ApplianceChangeExtListVO> result = applianceChangeMapper.selectList(pageWrap.getModel()); | 
|         if(result.size()>0){ | 
|             for(int i=0;i<result.size();i++){ | 
|                 ApplianceChangeExtListVO acev=result.get(i); | 
|   | 
|                 QueryApplianceChangeDetailExtDTO acd=new QueryApplianceChangeDetailExtDTO(); | 
|                 acd.setChaneId(acev.getId()); | 
|                 acd.setType(Constants.ONE); | 
|                 List<ApplianceChangeDetailExtListVO> listacd= applianceChangeDetialMapper.selectList(acd); | 
|                 Integer changenum=0; | 
|                 if(listacd!=null&&listacd.size()>0){ | 
|                     for(int j=0;j<listacd.size();j++){ | 
|                         ApplianceChangeDetailExtListVO acddata=listacd.get(j); | 
|   | 
|                             changenum=changenum+ acddata.getNum(); | 
|   | 
|                     } | 
|                     acev.setChangenum(changenum); | 
|                 /*    Appliances app= appliancesServiceimpl.findById(listacd.get(0).getApplianceId()); | 
|                    if(app!=null&&app.getQualityType()!=null){ | 
|                        acev.setQualityType(app.getQualityType()+""); | 
|                    }*/ | 
|   | 
|   | 
|                 } | 
|   | 
|             } | 
|         } | 
|   | 
|         return PageData.from(new PageInfo<>(result)); | 
|     } | 
|   | 
|     @Override | 
|     public long count(ApplianceChange applianceChange) { | 
|         QueryWrapper<ApplianceChange> wrapper = new QueryWrapper<>(applianceChange); | 
|         return applianceChangeMapper.selectCount(wrapper); | 
|     } | 
|   | 
|   | 
|     @Override | 
|     public synchronized  String  getNextCode(Integer comId ){ | 
|         String prefix = "GHD"+DateUtil.getDate(new Date(),"yyyyMMdd") +"-"; | 
|         Integer countNum  = RedisUtil.getObject(redisTemplate, Constants.RedisKeys.COM_APPLIANCECHANGER_CODE_KEY+comId,Integer.class); | 
|         countNum = Constants.formatIntegerNum(countNum)+1; | 
|         //更新缓存 | 
|         RedisUtil.addObject(redisTemplate,Constants.RedisKeys.COM_APPLIANCECHANGER_CODE_KEY+comId,countNum); | 
|         String nextIndex =Integer.toString( countNum); | 
|         return prefix + StringUtils.leftPad(nextIndex,4,"0"); | 
|     } | 
|   | 
| } |