package cn.com.goldenwater.dcproj.controller.base; import cn.com.goldenwater.dcproj.model.AttInspType; import cn.com.goldenwater.dcproj.param.AttInspTypeParam; import cn.com.goldenwater.dcproj.service.AttInspTypeService; import cn.com.goldenwater.core.web.BaseController; import cn.com.goldenwater.core.web.BaseResponse; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import org.apache.commons.lang3.StringUtils; import com.github.pagehelper.PageInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; import java.util.Collections; import java.util.Comparator; import java.util.List; /** * @author lune * @date 2019-7-19 */ @Api(value = "ATT 督查对象类型管理", tags = "ATT 督查对象类型管理") @RestController @RequestMapping("/att/insp/type") public class AttInspTypeController extends BaseController { private Logger logger = LoggerFactory.getLogger(getClass()); @Autowired private AttInspTypeService attInspTypeService; @ApiOperation(value = "添加/修改督查对象类型") @RequestMapping(value = "", method = RequestMethod.POST) public BaseResponse insert(@ApiParam(name = "attInspType", value = "AttInspType", required = true) @RequestBody AttInspType attInspType) { if (StringUtils.isBlank(attInspType.getCode())) { int codeMax = attInspTypeService.getMaxCode(); codeMax++; String code = String.valueOf(codeMax); if (String.valueOf(code).length() == 1) { code = "00" + code; } if (String.valueOf(code).length() == 2) { code = "0" + code; } attInspType.setCode(code); attInspTypeService.insert(attInspType); } else { attInspTypeService.update(attInspType); } return buildSuccessResponse(attInspType); } @ApiOperation(value = "根据ID删除督查对象类型") @RequestMapping(value = "/del/{id}", method = RequestMethod.GET) public BaseResponse delete(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) { int ret = attInspTypeService.delete(id); return buildSuccessResponse(); } @ApiOperation(value = "根据ID获取督查对象类型(单表)") @RequestMapping(value = "/{id}", method = RequestMethod.GET) public BaseResponse get(@ApiParam(name = "id", value = "id", required = true) @PathVariable String id) { AttInspType attInspType = attInspTypeService.get(id); return buildSuccessResponse(attInspType); } @ApiOperation(value = "获取督查对象类型(列表所有)") @RequestMapping(value = "/list", method = RequestMethod.POST) public BaseResponse> list(@ApiParam(name = "attInspTypeParam", value = "attInspTypeParam", required = true) @RequestBody AttInspTypeParam attInspTypeParam) { List attInspTypeList = attInspTypeService.findList(attInspTypeParam); Collections.sort(attInspTypeList, new Comparator() { @Override public int compare(AttInspType o1, AttInspType o2) { return Integer.valueOf(o1.getCode()) - Integer.valueOf(o2.getCode()); } }); return buildSuccessResponse(attInspTypeList); } @ApiOperation(value = "获取督查对象类型(列表--分页)") @RequestMapping(value = "/page", method = RequestMethod.POST) public BaseResponse> page(@ApiParam(name = "attInspTypeParam", value = "attInspTypeParam", required = true) @RequestBody AttInspTypeParam attInspTypeParam) { PageInfo attInspTypeList = attInspTypeService.findPageInfo(attInspTypeParam); return buildSuccessResponse(attInspTypeList); } @ApiOperation(value = "获取督查对象类型(列表所有,code去0)") @RequestMapping(value = "/getTypes", method = RequestMethod.POST) public BaseResponse> getTypes(@ApiParam(name = "attInspTypeParam", value = "attInspTypeParam", required = true) @RequestBody AttInspTypeParam attInspTypeParam) { List attInspTypeList = attInspTypeService.findList(attInspTypeParam); attInspTypeList.forEach(attInspType -> attInspType.setCode(String.valueOf(Integer.valueOf(attInspType.getCode())))); Collections.sort(attInspTypeList, new Comparator() { @Override public int compare(AttInspType o1, AttInspType o2) { return Integer.valueOf(o1.getCode()) - Integer.valueOf(o2.getCode()); } }); return buildSuccessResponse(attInspTypeList); } }