package com.zy.crm.manager.controller;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.mapper.Wrapper;
|
import com.baomidou.mybatisplus.plugins.Page;
|
import com.core.common.DateUtils;
|
import com.zy.crm.manager.entity.*;
|
import com.zy.crm.manager.service.*;
|
import com.core.annotations.ManagerAuth;
|
import com.core.common.BaseRes;
|
import com.core.common.Cools;
|
import com.core.common.R;
|
import com.core.domain.KeyValueVo;
|
import com.zy.crm.common.web.BaseController;
|
import com.zy.crm.system.entity.Role;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.util.ClassUtils;
|
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.multipart.MultipartFile;
|
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.*;
|
import java.text.SimpleDateFormat;
|
import java.util.*;
|
|
@RestController
|
public class PriOnlineController extends BaseController {
|
|
@Autowired
|
private PriOnlineService priOnlineService;
|
|
@Autowired
|
private PriService priService;
|
|
@Autowired
|
private PlanService planService;
|
|
@RequestMapping(value = "/priOnline/{id}/auth")
|
@ManagerAuth
|
public R get(@PathVariable("id") String id) {
|
return R.ok(priOnlineService.selectById(String.valueOf(id)));
|
}
|
|
@RequestMapping(value = "/priOnline/viewCheck/{id}/auth")
|
@ManagerAuth
|
public R viewCheck(@PathVariable("id") String id) {
|
PriOnline priOnline = priOnlineService.selectById(String.valueOf(id));
|
if (Cools.isEmpty(priOnline.getCheckData())) {
|
return R.error("请先上传询价");
|
}
|
return R.ok(priOnline);
|
}
|
|
@RequestMapping(value = "/priOnline/list/auth")
|
@ManagerAuth
|
public R list(@RequestParam(defaultValue = "1")Integer curr,
|
@RequestParam(defaultValue = "10")Integer limit,
|
@RequestParam(required = false)String orderByField,
|
@RequestParam(required = false)String orderByType,
|
@RequestParam(required = false)String condition,
|
@RequestParam Map<String, Object> param){
|
EntityWrapper<PriOnline> wrapper = new EntityWrapper<>();
|
wrapper.setSqlSelect("id,title,create_time as createTime,filepath,item_id as itemId,order_num as orderNum,template_name as templateName,user_id as userId,dept_id as deptId,status,update_time as updateTime,check_data as checkData,update_user_id as updateUserId,member_id as memberId");
|
wrapper.in("member_id", getUserRoleBelongsToUserId("allopen"));
|
excludeTrash(param);
|
convert(param, wrapper);
|
allLike(PriOnline.class, param.keySet(), wrapper, condition);
|
if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));}
|
return R.ok(priOnlineService.selectPage(new Page<>(curr, limit), wrapper));
|
}
|
|
private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){
|
boolean signUserId = false;
|
boolean signDeptId = false;
|
boolean signHostId = false;
|
for (Map.Entry<String, Object> entry : map.entrySet()){
|
if (entry.getKey().equals("dept_id")){
|
signDeptId = true;
|
if (String.valueOf(entry.getValue()).equals("19")){
|
signHostId = true;
|
}
|
}
|
}
|
for (Map.Entry<String, Object> entry : map.entrySet()){
|
String val = String.valueOf(entry.getValue());
|
if (val.contains(RANGE_TIME_LINK)){
|
String[] dates = val.split(RANGE_TIME_LINK);
|
wrapper.ge(entry.getKey(), DateUtils.convert(dates[0]));
|
wrapper.le(entry.getKey(), DateUtils.convert(dates[1]));
|
} else if (entry.getKey().equals("dept_id")){
|
if (!val.equals("19")){
|
wrapper.eq(entry.getKey(), val);
|
}
|
} else if (entry.getKey().equals("user_id") && !signDeptId){
|
signUserId = true;
|
wrapper.eq(entry.getKey(), val);
|
} else {
|
wrapper.like(entry.getKey(), val);
|
}
|
}
|
if (!signUserId && !signDeptId){
|
wrapper.eq("user_id", getUserId());
|
}
|
if (signHostId){
|
wrapper.or().eq("host_id",getHostId());
|
}
|
}
|
|
@RequestMapping(value = "/priOnline/add/auth")
|
@ManagerAuth
|
public R add(@RequestBody Map<String,Object> map) {
|
//获取模板名称
|
Pri pri = priService.selectById(Integer.parseInt(map.get("priId").toString()));
|
if (pri.getStatus() == 0) {
|
return R.error("该模板已被禁用");
|
}
|
|
PriOnline priOnline = new PriOnline();
|
priOnline.setCreateTime(new Date());
|
priOnline.setTitle(map.get("title").toString());
|
priOnline.setTemplateName(pri.getTitle());
|
priOnline.setSheetData(map.get("sheetData").toString());
|
priOnline.setItemId(Long.parseLong(map.get("itemId").toString()));
|
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
|
priOnline.setOrderNum(format.format(new Date()));
|
//创建人员
|
priOnline.setUserId(getUserId());
|
//创建人员部门
|
priOnline.setDeptId(getDeptId());
|
//更新时间
|
priOnline.setUpdateTime(new Date());
|
//更新人员
|
priOnline.setUpdateUserId(getUserId());
|
//状态,未完成
|
priOnline.setStatus(0);
|
//业务员
|
// Item item = itemService.selectById(priOnline.getItemId());
|
Plan plan = planService.selectById(priOnline.getItemId());
|
priOnline.setMemberId(plan.getUserId());
|
|
|
//设置项目流程
|
plan.setStep(2);
|
planService.updateById(plan);
|
|
priOnlineService.insert(priOnline);
|
return R.ok();
|
}
|
|
@RequestMapping(value = "/priOnline/addOther/auth")
|
@ManagerAuth
|
public R addOther(@RequestBody Map<String,Object> map) {
|
PriOnline online = priOnlineService.selectById(Long.parseLong(map.get("id").toString()));
|
|
PriOnline priOnline = new PriOnline();
|
priOnline.setCreateTime(new Date());
|
priOnline.setTitle(map.get("title").toString());
|
priOnline.setTemplateName(online.getTemplateName());
|
priOnline.setSheetData(map.get("sheetData").toString());
|
priOnline.setItemId(online.getItemId());
|
|
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
|
priOnline.setOrderNum(format.format(new Date()));
|
//创建人员
|
priOnline.setUserId(getUserId());
|
//更新时间
|
priOnline.setUpdateTime(new Date());
|
//更新人员
|
priOnline.setUpdateUserId(getUserId());
|
//状态,未完成
|
priOnline.setStatus(0);
|
priOnline.setDeptId(getDeptId());
|
//业务员
|
// Item item = itemService.selectById(priOnline.getItemId());
|
Plan plan = planService.selectById(priOnline.getItemId());
|
priOnline.setMemberId(plan.getUserId());
|
|
priOnlineService.insert(priOnline);
|
return R.ok();
|
}
|
|
@RequestMapping(value = "/priOnline/update/auth")
|
@ManagerAuth
|
public R update(@RequestBody Map<String,Object> map){
|
PriOnline priOnline = priOnlineService.selectById(Long.parseLong(map.get("id").toString()));
|
if (priOnline.getStatus() == 1) {
|
return R.error("核价已完成,禁止保存");
|
}
|
priOnline.setTitle(map.get("title").toString());
|
priOnline.setSheetData(map.get("sheetData").toString());
|
//更新人员
|
priOnline.setUpdateUserId(getUserId());
|
//更新时间
|
priOnline.setUpdateTime(new Date());
|
priOnlineService.updateById(priOnline);
|
return R.ok();
|
}
|
|
//更新状态
|
@RequestMapping(value = "/priOnline/updateForm/auth")
|
@ManagerAuth
|
public R updateForm(Long id,Integer status,String title,String templateName){
|
PriOnline priOnline = priOnlineService.selectById(id);
|
priOnline.setStatus(status);
|
priOnline.setUpdateTime(new Date());
|
priOnline.setTitle(title);
|
priOnline.setTemplateName(templateName);
|
priOnlineService.updateById(priOnline);
|
return R.ok();
|
}
|
|
@RequestMapping(value = "/priOnline/uploadCheck/auth")
|
@ManagerAuth
|
public R uploadCheck(@RequestParam("id") Integer id,
|
@RequestParam("checkData") String checkData,
|
@RequestParam("file") MultipartFile[] files){
|
PriOnline priOnline = priOnlineService.selectById(id);
|
if (priOnline.getStatus() == 1) {
|
return R.error("核价已完成,禁止上传");
|
}
|
priOnline.setCheckData(checkData);
|
|
|
MultipartFile file = files[0];
|
SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd_HHmmss");
|
String path = ClassUtils.getDefaultClassLoader().getResource("excel/uploadCheckData").getPath();
|
//文件后缀名
|
String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
|
//上传文件名
|
String filename = format.format(new Date()) + suffix;
|
//最终文件路径
|
String filepath = path + "/" + filename;
|
|
|
//服务器端保存的文件对象
|
File serverFile = new File(filepath);
|
if(!serverFile.exists()) {
|
try {
|
//创建文件
|
serverFile.createNewFile();
|
//将上传的文件写入到服务器端文件内
|
file.transferTo(serverFile);
|
} catch (IOException e) {
|
e.printStackTrace();
|
}
|
}
|
|
//保存文件名
|
priOnline.setCheckDataFile(filename);
|
priOnlineService.updateById(priOnline);
|
return R.ok();
|
}
|
|
@GetMapping("/priOnline/checkDataDownload/{filename}")
|
public void download(@PathVariable String filename, HttpServletResponse response) {
|
try {
|
ClassPathResource pathResource = new ClassPathResource("excel/uploadCheckData/" + filename);
|
File file = pathResource.getFile();
|
InputStream inputStream = pathResource.getInputStream();
|
//输出文件
|
InputStream fis = new BufferedInputStream(inputStream);
|
byte[] buffer = new byte[fis.available()];
|
fis.read(buffer);
|
fis.close();
|
response.reset();
|
|
//获取文件的名字再浏览器下载页面
|
String name = file.getName();
|
response.addHeader("Content-Disposition", "attachment;filename=" + new String(name.getBytes(), "iso-8859-1"));
|
response.addHeader("Content-Length", "" + file.length());
|
OutputStream out = new BufferedOutputStream(response.getOutputStream());
|
response.setContentType("application/octet-stream");
|
out.write(buffer);
|
out.flush();
|
out.close();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
@RequestMapping(value = "/priOnline/delete/auth")
|
@ManagerAuth
|
public R delete(Long[] ids){
|
if (Cools.isEmpty(ids)){
|
return R.error();
|
}
|
priOnlineService.deleteBatchIds(Arrays.asList(ids));
|
return R.ok();
|
}
|
|
@RequestMapping(value = "/priOnline/export/auth")
|
@ManagerAuth
|
public R export(@RequestBody JSONObject param){
|
EntityWrapper<PriOnline> wrapper = new EntityWrapper<>();
|
List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class);
|
Map<String, Object> map = excludeTrash(param.getJSONObject("priOnline"));
|
convert(map, wrapper);
|
List<PriOnline> list = priOnlineService.selectList(wrapper);
|
return R.ok(exportSupport(list, fields));
|
}
|
|
@RequestMapping(value = "/priOnlineQuery/auth")
|
@ManagerAuth
|
public R query(String condition) {
|
EntityWrapper<PriOnline> wrapper = new EntityWrapper<>();
|
wrapper.like("order_num", condition);
|
wrapper.in("member_id", getUserRoleBelongsToUserId("allopen"));
|
Page<PriOnline> page = priOnlineService.selectPage(new Page<>(0, 10), wrapper);
|
List<Map<String, Object>> result = new ArrayList<>();
|
for (PriOnline priOnline : page.getRecords()){
|
Map<String, Object> map = new HashMap<>();
|
map.put("id", priOnline.getId());
|
map.put("value", priOnline.getOrderNum() + "/" + priOnline.getPlanId$() + "/" + priOnline.getMemberId$());
|
result.add(map);
|
}
|
return R.ok(result);
|
}
|
|
@RequestMapping(value = "/priOnline/check/column/auth")
|
@ManagerAuth
|
public R query(@RequestBody JSONObject param) {
|
Wrapper<PriOnline> wrapper = new EntityWrapper<PriOnline>().eq(humpToLine(String.valueOf(param.get("key"))), param.get("val"));
|
if (null != priOnlineService.selectOne(wrapper)){
|
return R.parse(BaseRes.REPEAT).add(getComment(PriOnline.class, String.valueOf(param.get("key"))));
|
}
|
return R.ok();
|
}
|
|
@RequestMapping("/priOnline/all/get/kv")
|
@ManagerAuth
|
public R getDataKV(@RequestParam(required = false) String condition) {
|
List<KeyValueVo> vos = new ArrayList<>();
|
Wrapper<PriOnline> wrapper = new EntityWrapper<PriOnline>().andNew().like("id", condition).orderBy("create_time", false);
|
priOnlineService.selectPage(new Page<>(1, 30), wrapper).getRecords().forEach(item -> vos.add(new KeyValueVo(String.valueOf(item.getId()), item.getId())));
|
return R.ok().add(vos);
|
}
|
|
}
|