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.annotations.ManagerAuth;
|
import com.core.common.BaseRes;
|
import com.core.common.Cools;
|
import com.core.common.DateUtils;
|
import com.core.common.R;
|
import com.core.domain.KeyValueVo;
|
import com.zy.crm.common.web.BaseController;
|
import com.zy.crm.manager.entity.PlanType;
|
import com.zy.crm.manager.service.PlanTypeService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
import java.util.*;
|
|
@RestController
|
public class PlanTypeController extends BaseController {
|
|
@Autowired
|
private PlanTypeService planTypeService;
|
|
@GetMapping(value = "/planType/{id}/auth")
|
@ManagerAuth
|
public R get(@PathVariable("id") String id) {
|
return R.ok(planTypeService.selectById(String.valueOf(id)));
|
}
|
|
@PostMapping(value = "/planType/list/auth")
|
public R list() {
|
return R.ok().add(planTypeService.selectList(new EntityWrapper<PlanType>().orderBy("id")));
|
}
|
|
@PostMapping(value = "/planType/list/radio/auth")
|
public R listRadio() {
|
List<PlanType> planTypes = planTypeService.selectList(new EntityWrapper<PlanType>().orderBy("id"));
|
for (int i = 0; i<planTypes.size(); i++) {
|
planTypes.get(i).setData("");
|
planTypes.get(i).setHtml("");
|
if (i == 0) {
|
planTypes.get(i).setChecked("checked");
|
}
|
}
|
return R.ok().add(planTypes);
|
}
|
|
@RequestMapping(value = "/planType/page/auth")
|
@ManagerAuth
|
public R page(@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<PlanType> wrapper = new EntityWrapper<>();
|
excludeTrash(param);
|
convert(param, wrapper);
|
allLike(PlanType.class, param.keySet(), wrapper, condition);
|
if (!Cools.isEmpty(orderByField)){wrapper.orderBy(humpToLine(orderByField), "asc".equals(orderByType));}
|
return R.ok(planTypeService.selectPage(new Page<>(curr, limit), wrapper));
|
}
|
|
private <T> void convert(Map<String, Object> map, EntityWrapper<T> wrapper){
|
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 {
|
wrapper.like(entry.getKey(), val);
|
}
|
}
|
}
|
|
@RequestMapping(value = "/planType/add/auth")
|
@ManagerAuth
|
public R add(PlanType planType) {
|
planType.setHostId(getHostId());
|
planType.setCreateBy(getUserId());
|
planType.setCreateTime(new Date());
|
planType.setUpdateBy(getUserId());
|
planType.setUpdateTime(new Date());
|
planType.setStatus(1);
|
planTypeService.insert(planType);
|
return R.ok();
|
}
|
|
@RequestMapping(value = "/planType/update/auth")
|
@ManagerAuth
|
public R update(PlanType planType){
|
if (Cools.isEmpty(planType) || null==planType.getId()){
|
return R.error();
|
}
|
planType.setUpdateBy(getUserId());
|
planType.setUpdateTime(new Date());
|
planTypeService.updateById(planType);
|
return R.ok();
|
}
|
|
@RequestMapping(value = "/planType/delete/auth")
|
@ManagerAuth
|
public R delete(@RequestParam(value="ids[]") Long[] ids){
|
for (Long id : ids){
|
planTypeService.deleteById(id);
|
}
|
return R.ok();
|
}
|
|
@RequestMapping(value = "/planType/export/auth")
|
@ManagerAuth
|
public R export(@RequestBody JSONObject param){
|
EntityWrapper<PlanType> wrapper = new EntityWrapper<>();
|
List<String> fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class);
|
Map<String, Object> map = excludeTrash(param.getJSONObject("planType"));
|
convert(map, wrapper);
|
List<PlanType> list = planTypeService.selectList(wrapper);
|
return R.ok(exportSupport(list, fields));
|
}
|
|
@RequestMapping(value = "/planTypeQuery/auth")
|
@ManagerAuth
|
public R query(String condition) {
|
EntityWrapper<PlanType> wrapper = new EntityWrapper<>();
|
wrapper.like("name", condition);
|
Page<PlanType> page = planTypeService.selectPage(new Page<>(0, 10), wrapper);
|
List<Map<String, Object>> result = new ArrayList<>();
|
for (PlanType planType : page.getRecords()){
|
Map<String, Object> map = new HashMap<>();
|
map.put("id", planType.getId());
|
map.put("value", planType.getName());
|
result.add(map);
|
}
|
return R.ok(result);
|
}
|
|
@RequestMapping(value = "/planType/check/column/auth")
|
@ManagerAuth
|
public R query(@RequestBody JSONObject param) {
|
Wrapper<PlanType> wrapper = new EntityWrapper<PlanType>().eq(humpToLine(String.valueOf(param.get("key"))), param.get("val"));
|
if (null != planTypeService.selectOne(wrapper)){
|
return R.parse(BaseRes.REPEAT).add(getComment(PlanType.class, String.valueOf(param.get("key"))));
|
}
|
return R.ok();
|
}
|
|
@RequestMapping("/planType/all/get/kv")
|
@ManagerAuth
|
public R getDataKV(@RequestParam(required = false) String condition) {
|
List<KeyValueVo> vos = new ArrayList<>();
|
Wrapper<PlanType> wrapper = new EntityWrapper<PlanType>().andNew().like("name", condition).orderBy("create_time", false);
|
planTypeService.selectPage(new Page<>(1, 30), wrapper).getRecords().forEach(item -> vos.add(new KeyValueVo(String.valueOf(item.getName()), item.getId())));
|
return R.ok().add(vos);
|
}
|
|
}
|