package com.zy.asrs.controller; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.plugins.Page; import com.core.annotations.ManagerAuth; import com.core.common.Cools; import com.core.common.DateUtils; import com.core.common.R; import com.zy.asrs.entity.ConfigType; import com.zy.asrs.service.ConfigTypeService; import com.zy.common.web.BaseController; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import java.util.*; @RestController public class ConfigTypeController extends BaseController { @Autowired private ConfigTypeService configTypeService; @RequestMapping(value = "/cinfigType/{id}/auth") @ManagerAuth public R get(@PathVariable("id") Long id) { return R.ok(configTypeService.selectById(String.valueOf(id))); } @RequestMapping(value = "/cinfigType/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 Map param){ excludeTrash(param); EntityWrapper wrapper = new EntityWrapper<>(); convert(param, wrapper); wrapper.orderBy("id", false); return R.ok(configTypeService.selectPage(new Page<>(curr, limit), wrapper)); } @RequestMapping(value = "/configType/add/auth") @ManagerAuth public R add(ConfigType configType){ if (Cools.isEmpty(configType)){ return R.error(); } configType.setCreateTime(new Date()); configTypeService.insert(configType); return R.ok(); } @RequestMapping(value = "/configType/delete/auth") @ManagerAuth public R delete(Long id){ configTypeService.deleteById(id); return R.ok(); } @RequestMapping(value = "/configTypeQuery/auth") @ManagerAuth public R query(String condition) { String type = condition.split(",")[1]; condition = condition.split(",")[0]; EntityWrapper wrapper = new EntityWrapper<>(); wrapper.eq("type",type); wrapper.like("value", condition); Page page = configTypeService.selectPage(new Page<>(0, 32), wrapper); List> result = new ArrayList<>(); for (ConfigType configType : page.getRecords()){ Map map = new HashMap<>(); map.put("id", configType.getId()); map.put("value", configType.getValue()); result.add(map); } return R.ok(result); } private void convert(Map map, EntityWrapper wrapper){ for (Map.Entry 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); } } } }