package com.gk.firework.Service.ServiceImpl;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.gk.firework.Domain.Exception.BusinessException;
|
import com.gk.firework.Domain.StandardTemplate1;
|
import com.gk.firework.Domain.UserInfo;
|
import com.gk.firework.Domain.Utils.Properties;
|
import com.gk.firework.Domain.Utils.StringUtils;
|
import com.gk.firework.Domain.Utils.UploadUtil;
|
import com.gk.firework.Domain.Vo.StandardTemplate1Vo;
|
import com.gk.firework.Mapper.StandardTemplate1Mapper;
|
import com.gk.firework.Service.StandardTemplate1Service;
|
import com.gk.firework.Service.UserService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.Map;
|
import java.util.List;
|
|
@Service("standardTemplate1Service")
|
public class StandardTemplate1ServiceImpl extends ServiceImpl<StandardTemplate1Mapper, StandardTemplate1> implements StandardTemplate1Service {
|
|
@Autowired
|
private StandardTemplate1Mapper standardTemplate1Mapper;
|
@Autowired
|
private UserService userService;
|
|
@Override
|
public IPage selectPage(Page<StandardTemplate1> page, Map filter, UserInfo userInfo) {
|
|
UserInfo user = userService.getById(userInfo.getId());
|
Map<String, Object> params = new HashMap<>();
|
//菜单
|
params.put("menu", filter.get("menu"));
|
params.put("type", filter.get("type"));
|
//可视权限
|
{
|
params.put("enterprisenumber", user.getCompanynumber());
|
params.put("province", user.getProvince());
|
params.put("city", user.getCity());
|
params.put("district", user.getArea());
|
params.put("street", user.getTown());
|
params.put("committee", user.getCommunity());
|
}
|
|
params.put("filterProvince", filter.get("province"));
|
params.put("filterCity", filter.get("city"));
|
params.put("filterDistrict", filter.get("district"));
|
params.put("filterStreet", filter.get("street"));
|
params.put("filterCommittee", filter.get("committee"));
|
params.put("safetysupervision", filter.get("safetysupervision"));
|
params.put("enterprisename", filter.get("enterprisename"));
|
List<StandardTemplate1> list = standardTemplate1Mapper.selectPages(page, params);
|
return page.setRecords(list);
|
}
|
|
|
@Override
|
@Transactional
|
public void addStandard(StandardTemplate1Vo standardTemplate1Vo, UserInfo user) {
|
|
if (standardTemplate1Vo.getFile() == null) {
|
throw new BusinessException("未上传文件");
|
}
|
if (StringUtils.isBlank(standardTemplate1Vo.getMenu())) {
|
throw new BusinessException("菜单发生错误");
|
}
|
|
UserInfo userInfo = userService.getById(user.getId());
|
StandardTemplate1 template1 = new StandardTemplate1();
|
template1.setMenu(standardTemplate1Vo.getMenu());
|
template1.setSettime(standardTemplate1Vo.getSettime());
|
template1.setEnterprisenumber(userInfo.getCompanynumber());
|
template1.setEnterprisename(userInfo.getUsername());
|
template1.setName(standardTemplate1Vo.getName());
|
template1.setCreatetime(new Date());
|
template1.setCreateby(user.getId());
|
template1.setCreatebyname(user.getUsername());
|
template1.setValidflag(true);
|
template1.setType(standardTemplate1Vo.getType());
|
template1.setContent(standardTemplate1Vo.getContent());
|
|
|
try {
|
String name = UploadUtil.uploadFile(standardTemplate1Vo.getFile(), Properties.standardPath);
|
template1.setFilename(standardTemplate1Vo.getFile().getOriginalFilename());
|
template1.setUrl(Properties.standard + name);
|
} catch (Exception e) {
|
throw new BusinessException("上传发生错误");
|
}
|
|
this.save(template1);
|
|
|
}
|
|
/**
|
* @Description: 修改简单模板
|
* @date 2021/4/30 16:15
|
*/
|
@Override
|
public void modStandard(StandardTemplate1Vo standardTemplate1Vo, UserInfo user) {
|
|
|
if (StringUtils.isBlank(standardTemplate1Vo.getMenu())) {
|
throw new BusinessException("菜单发生错误");
|
}
|
|
UserInfo userInfo = userService.getById(user.getId());
|
StandardTemplate1 template1 = new StandardTemplate1();
|
template1.setId(standardTemplate1Vo.getId());
|
template1.setMenu(standardTemplate1Vo.getMenu());
|
template1.setSettime(standardTemplate1Vo.getSettime());
|
template1.setEnterprisenumber(userInfo.getCompanynumber());
|
template1.setEnterprisename(userInfo.getUsername());
|
template1.setName(standardTemplate1Vo.getName());
|
template1.setCreatetime(new Date());
|
template1.setCreateby(user.getId());
|
template1.setCreatebyname(user.getUsername());
|
template1.setValidflag(true);
|
template1.setType(standardTemplate1Vo.getType());
|
template1.setContent(standardTemplate1Vo.getContent());
|
try {
|
if (standardTemplate1Vo.getFile() != null) {
|
String name = UploadUtil.uploadFile(standardTemplate1Vo.getFile(), Properties.standardPath);
|
template1.setFilename(standardTemplate1Vo.getFile().getOriginalFilename());
|
template1.setUrl(Properties.standard + name);
|
}
|
|
} catch (Exception e) {
|
throw new BusinessException("上传发生错误");
|
}
|
|
this.updateById(template1);
|
|
}
|
|
/**
|
* @Description: 删除简单模板
|
* @date 2021/4/30 16:25
|
*/
|
@Override
|
public void delStandard(Long id, UserInfo user) {
|
LambdaUpdateWrapper<StandardTemplate1> updateWrapper = new LambdaUpdateWrapper<>();
|
updateWrapper.set(StandardTemplate1::getValidflag, false)
|
.set(StandardTemplate1::getUpdatetime, new Date())
|
.set(StandardTemplate1::getUpdateby, user.getId())
|
.set(StandardTemplate1::getUpdatebyname,user.getUsername())
|
.eq(StandardTemplate1::getId, id);
|
this.update(updateWrapper);
|
}
|
|
|
}
|