# DrawerCountNumberConfigController.java

    package cloud.wconnect.frontoffice.controller.drawercount;

    import cloud.wconnect.commonlib.annotation.ApiId;
    import cloud.wconnect.commonlib.component.BeanMapper;
    import cloud.wconnect.commonlib.component.SessionContext;
    import cloud.wconnect.commonlib.util.UpdateLogUtil;
    import cloud.wconnect.frontoffice.cons.drawercount.DrawerCountCons;
    import cloud.wconnect.frontoffice.entity.drawercount.DrawerCountNumberConfig;
    import cloud.wconnect.frontoffice.pojo.dto.drawercount.DrawerNumberConfigDTO;
    import cloud.wconnect.frontoffice.service.drawercount.IDrawerCountNumberConfigService;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.web.bind.annotation.*;

    import jakarta.validation.Valid;
    import java.util.Collections;
    import java.util.Map;
    import java.util.Objects;

    /**
     * <p>
     * Drawer Count功能的抽屉数量配置表 前端控制器
     * </p>
     *
     * @author zc
     * @since 2023-08-24
     */
    @RestController
    @RequestMapping("/shift-drawer-count/drawer-count-number-config")
    public class DrawerCountNumberConfigController {

        @Autowired
        private IDrawerCountNumberConfigService drawerCountNumberConfigService;

        @Autowired
        private SessionContext sessionContext;
        @Autowired
        private UpdateLogUtil updateLogUtil;
        @Autowired
        private BeanMapper beanMapper;

        /**
         * 查询抽屉数量配置
         *
         * @param property 资产标识
         * @return DrawerNumberConfigDTO
         * @author zc
         * @date 2023/8/24
         */
        @ApiId(596)
        @GetMapping
        public DrawerNumberConfigDTO get(String property) {
            int propertyId = sessionContext.getPropertyId(property);
            DrawerCountNumberConfig drawerCountNumberConfig = drawerCountNumberConfigService.get(propertyId);
            if (Objects.isNull(drawerCountNumberConfig)) {
                return new DrawerNumberConfigDTO(DrawerCountCons.DEFAULT_DRAWER_NUMBER);
            }
            return beanMapper.map(drawerCountNumberConfig, DrawerNumberConfigDTO.class);
        }

        /**
         * 保存抽屉数量配置
         *
         * @param property        资产标识
         * @param numberConfigDTO 抽屉数量
         * @return empty map
         * @author zc
         * @date 2023/8/24
         */
        @ApiId(597)
        @PostMapping
        public Map<Object, Object> save(String property, @RequestBody @Valid DrawerNumberConfigDTO numberConfigDTO) {
            int propertyId = sessionContext.getPropertyId(property);
            int loginUserId = sessionContext.getLoginUserId();

            DrawerCountNumberConfig drawerCountNumberConfig = new DrawerCountNumberConfig();
            drawerCountNumberConfig.setDrawerNumber(numberConfigDTO.getDrawerNumber());

            DrawerCountNumberConfig originConfig = drawerCountNumberConfigService.get(propertyId);
            if (Objects.nonNull(originConfig)) {
                drawerCountNumberConfig.setId(originConfig.getId());
                drawerCountNumberConfig.setUpdateLog(updateLogUtil.append(originConfig.getUpdateLog(), loginUserId));
            } else {
                drawerCountNumberConfig.setPropertyId(propertyId);
                drawerCountNumberConfig.setUpdateLog(updateLogUtil.get(loginUserId));
            }

            // 保存
            drawerCountNumberConfigService.saveOrUpdate(drawerCountNumberConfig);
            return Collections.emptyMap();
        }
    }