# DrawerCountAmountConfigController.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.DrawerCountAmountConfig;
    import cloud.wconnect.frontoffice.pojo.dto.drawercount.DrawerInitConfigDTO;
    import cloud.wconnect.frontoffice.service.drawercount.IDrawerCountAmountConfigService;
    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功能的init amount配置表 前端控制器
     * </p>
     *
     * @author lichen
     * @since 2023-04-06
     */
    @RestController
    @RequestMapping("/shift-drawer-count/drawer-count-amount-config")
    public class DrawerCountAmountConfigController {

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

        /**
         * 查询抽屉初始金额
         *
         * @param property 资产标识
         * @return DrawerInitConfigDTO
         * @author zc
         * @date 2023/8/25
         */
        @ApiId(282)
        @GetMapping
        public DrawerInitConfigDTO get(String property) {
            int propertyId = sessionContext.getPropertyId(property);
            DrawerCountAmountConfig drawerCountAmountConfig = drawerCountAmountConfigService.get(propertyId);
            if (Objects.isNull(drawerCountAmountConfig)) {
                return new DrawerInitConfigDTO(DrawerCountCons.DEFAULT_DRAWER_INIT);
            }
            return beanMapper.map(drawerCountAmountConfig, DrawerInitConfigDTO.class);
        }

        /**
         * 保存抽屉初始金额
         *
         * @param property      资产标识
         * @param initConfigDTO 初始金额配置
         * @return empty map
         * @author zc
         * @date 2023/8/25
         */
        @ApiId(283)
        @PostMapping
        public Map<Object, Object> save(String property, @RequestBody @Valid DrawerInitConfigDTO initConfigDTO) {
            int propertyId = sessionContext.getPropertyId(property);
            int loginUserId = sessionContext.getLoginUserId();

            DrawerCountAmountConfig drawerCountAmountConfig = new DrawerCountAmountConfig();
            drawerCountAmountConfig.setDrawerInit(initConfigDTO.getDrawerInit());

            DrawerCountAmountConfig originConfig = drawerCountAmountConfigService.get(propertyId);
            if (Objects.nonNull(originConfig)) {
                drawerCountAmountConfig.setId(originConfig.getId());
                drawerCountAmountConfig.setUpdateLog(updateLogUtil.append(originConfig.getUpdateLog(), loginUserId));
            } else {
                drawerCountAmountConfig.setPropertyId(propertyId);
                drawerCountAmountConfig.setUpdateLog(updateLogUtil.get(loginUserId));
            }

            // 保存
            drawerCountAmountConfigService.saveOrUpdate(drawerCountAmountConfig);
            return Collections.emptyMap();
        }
    }