package zy.cloud.wms.system.controller; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.mapper.EntityWrapper; import com.baomidou.mybatisplus.plugins.Page; import zy.cloud.wms.common.web.BaseController; import zy.cloud.wms.manager.entity.DocType; import zy.cloud.wms.system.entity.Host; import zy.cloud.wms.system.service.HostService; import com.core.annotations.ManagerAuth; import com.core.common.Cools; import com.core.common.DateUtils; import com.core.common.R; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.*; @RestController public class HostController extends BaseController { @Autowired private HostService hostService; @RequestMapping(value = "/host/{id}/auth") @ManagerAuth public R get(@PathVariable("id") Long id) { return R.ok(hostService.selectById(String.valueOf(id))); } @RequestMapping(value = "/host/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", true); // Long hostId = getHostId(); // if (null != hostId) { // wrapper.eq("id", hostId); // } return R.ok(hostService.selectPage(new Page<>(curr, limit), wrapper)); } 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); } } } @RequestMapping(value = "/host/add/auth") @ManagerAuth public R add(Host host) { if (getUserId() != 9527) { if (getUser().getRoleId() != 1) { return R.error("权限不足"); } } host.setCreateTime(new Date()); host.setUpdateTime(new Date()); host.setStatus(1); hostService.insert(host); return R.ok(); } @RequestMapping(value = "/host/update/auth") @ManagerAuth public R update(Host host){ if (Cools.isEmpty(host) || null==host.getId()){ return R.error(); } host.setUpdateTime(new Date()); hostService.updateById(host); return R.ok(); } @RequestMapping(value = "/host/delete/one/auth") @ManagerAuth public R deleteOne(@RequestParam String param){ if (getUserId() != 9527) { if (getUser().getRoleId() != 1) { return R.error("权限不足"); } } Host host = JSONArray.parseObject(param, Host.class); if (Cools.isEmpty(host)){ return R.error(); } hostService.delete(new EntityWrapper<>(host)); return R.ok(); } @RequestMapping(value = "/host/delete/auth") @ManagerAuth public R delete(@RequestParam(value="ids[]") Long[] ids){ for (Long id : ids){ hostService.deleteById(id); } return R.ok(); } @RequestMapping(value = "/host/export/auth") @ManagerAuth public R export(@RequestBody JSONObject param){ List fields = JSONObject.parseArray(param.getJSONArray("fields").toJSONString(), String.class); EntityWrapper wrapper = new EntityWrapper<>(); Map map = excludeTrash(param.getJSONObject("host")); convert(map, wrapper); List list = hostService.selectList(wrapper); return R.ok(exportSupport(list, fields)); } @RequestMapping(value = "/hostQuery/auth") @ManagerAuth public R query(String condition) { EntityWrapper wrapper = new EntityWrapper<>(); wrapper.like("name", condition); Long hostId = getHostId(); if (null != hostId) { wrapper.eq("id", hostId); } Page page = hostService.selectPage(new Page<>(0, 10), wrapper); List> result = new ArrayList<>(); for (Host host : page.getRecords()){ Map map = new HashMap<>(); map.put("id", host.getId()); map.put("value", host.getName()); result.add(map); } return R.ok(result); } }